Skip to content

Instantly share code, notes, and snippets.

@felipecastrosales
Created April 26, 2022 14:07
Show Gist options
  • Save felipecastrosales/afe80bcb8029b24fe10d3578a66be672 to your computer and use it in GitHub Desktop.
Save felipecastrosales/afe80bcb8029b24fe10d3578a66be672 to your computer and use it in GitHub Desktop.
Singleton
class SingletonOne {
SingletonOne._privateConstructor();
static final _instance = SingletonOne._privateConstructor();
factory SingletonOne() {
return _instance;
}
}
class SingletonTwo {
SingletonTwo._privateConstructor();
static final _instance = SingletonTwo._privateConstructor();
static SingletonTwo get instance => _instance;
}
class SingletonThree {
SingletonThree._privateConstructor();
static final instance = SingletonThree._privateConstructor();
}
void main() {
SingletonOne one = SingletonOne();
SingletonTwo two = SingletonTwo.instance;
SingletonThree three = SingletonThree.instance;
print(one);
print(two);
print(three);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment