Flutter/dart/singleton
提供: 初心者エンジニアの簡易メモ
class SingletonHoge {
String name = "";
static final SingletonHoge _singleton = SingletonHoge._internal();
factory SingletonHoge() {
return _singleton;
}
SingletonHoge._internal() {
// init
}
}
SingletonHoge hoge = SingletonHoge(); print (hoge.name); // "" hoge.name = "taro"; print (hoge.name); // "taro"
https://stackoverflow.com/questions/12649573/how-do-you-build-a-singleton-in-dart
