Created
April 23, 2022 09:42
-
-
Save taznica/6308669c891b61b89e26bae874d8feb7 to your computer and use it in GitHub Desktop.
This file contains 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 Singleton { | |
static final Singleton _singleton = Singleton._(); | |
factory Singleton() { | |
return _singleton; | |
} | |
Singleton._(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
static
final
Singleton._()
が呼ばれて_singleton
に代入され、2度目以降は_singleton
は代入(変更)されないfactory
Singleton._();
Singleton._();
_
から始まると private constructor になる_internal()
などでもいいReferences
https://stackoverflow.com/a/12649574
https://flutterbyexample.com/lesson/singletons