Skip to content

Instantly share code, notes, and snippets.

@II11II
Last active December 16, 2021 09:22
Show Gist options
  • Save II11II/067a3c1c05f9ee8c68e859b945a2e41f to your computer and use it in GitHub Desktop.
Save II11II/067a3c1c05f9ee8c68e859b945a2e41f to your computer and use it in GitHub Desktop.
Lazy initialization in dart
void main() {
print("entry point");
print(string);
print(string);
print(customClass);
print(customClass);
print("exit point");
}
String string = () {
print("It initialises only once");
return "Lorem ipsum";
}();
CustomClass customClass = () {
print("It initialises object only once");
return CustomClass();
}();
class CustomClass {
CustomClass() {
print("CustomClass constructor called");
}
@override
String toString() => "CustomClass";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment