Skip to content

Instantly share code, notes, and snippets.

@roipeker
Created May 1, 2020 04:40
Show Gist options
  • Save roipeker/7f74da934651e473348e9e02db65d207 to your computer and use it in GitHub Desktop.
Save roipeker/7f74da934651e473348e9e02db65d207 to your computer and use it in GitHub Desktop.
Dart's factory singleton
void main(List<String> arguments) {
var a1 = Storage();
var a2 = Storage();
print(a1.hashCode);
print(a2.hashCode);
print(a1==a2);
}
class Storage {
static final Storage _singleton = Storage._internal();
factory Storage() => _singleton;
Storage._internal(){
print('initialize code here...');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment