Skip to content

Instantly share code, notes, and snippets.

@iAmWillShepherd
Last active February 25, 2022 17:05
Show Gist options
  • Save iAmWillShepherd/a0b1a1da0bbac7504b4064e6c5edca1b to your computer and use it in GitHub Desktop.
Save iAmWillShepherd/a0b1a1da0bbac7504b4064e6c5edca1b to your computer and use it in GitHub Desktop.
Lazily initialize variables in Dart using the late keyword
void main() {
late String s = superCostlyInitializer(); // `s` is not initialized yet
print(s); // `s` is initialized now that it's needed
}
String superCostlyInitializer() {
return "A lot of work went into initializing this result";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment