Created
October 22, 2020 17:22
-
-
Save timsneath/1d5c7ec2ca86db4b81082e0691787bab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class StatusLine extends StatelessWidget { | |
final Status status; | |
StatusLine({this.status: Status.failed}); | |
@override | |
Widget build(BuildContext context) { | |
// This local variable is non-nullable, but not initialized. | |
String statusText; | |
if (status == Status.ok) { | |
statusText = 'Update succeeded'; | |
} else { | |
statusText = 'Update failed'; | |
} | |
// By this point, Dart knows statusText isn't null, as we've | |
// assigned a value in both the if- and else-statements. Thus | |
// we can pass it to the Text widget -- which doesn't accept | |
// nullable Strings -- without getting an error. | |
return Text(statusText); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment