is singleton design pattern possible in dart code example
Example 1: singleton classes in dart example
class Singleton {
static Singleton _instance;
Singleton._internal();
static Singleton getInstance() {
if (_instance == null) {
_instance = Singleton._internal();
}
return _instance;
}
}
Example 2: singleton classes in dart example
class Singleton {
static Singleton _instance;
Singleton._internal() {
_instance = this;
}
factory Singleton() => _instance ?? Singleton._internal();
}