Skip to content

Instantly share code, notes, and snippets.

@RedBrogdon
Last active June 9, 2020 16:42
Show Gist options
  • Save RedBrogdon/e564e4dc6a1b8467d4a8715fb21baf00 to your computer and use it in GitHub Desktop.
Save RedBrogdon/e564e4dc6a1b8467d4a8715fb21baf00 to your computer and use it in GitHub Desktop.
Snippet 4: Definite assignment
// 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