Last active
June 9, 2020 16:42
-
-
Save RedBrogdon/e564e4dc6a1b8467d4a8715fb21baf00 to your computer and use it in GitHub Desktop.
Snippet 4: Definite assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dart's type system is crafty enough to track | |
// where variables are assigned and where their | |
// values are read, and to verify that | |
// non-nullable fields are given values | |
// before any code tries to read from them. | |
// | |
// This process is called "definite assignment." | |
// | |
// Try uncommenting the if-else statement in the | |
// code below, and watch the analyzer errors | |
// disappear. | |
void main() { | |
String text; | |
// if (DateTime.now().hour < 12) { | |
// text = "It's morning! Let's make aloo paratha!"; | |
// } else { | |
// text = "It's afternoon! Let's make biryani!"; | |
// } | |
print(text); | |
print(text.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment