Dart 单例模式
class Service {
// 工厂模式
factory Service() =>_getInstance();
static Service get instance => _getInstance();
static Service _instance;
Service._internal() {
// 初始化
}
static Service _getInstance() {
if (_instance == null) {
_instance = new Service._internal();
}
return _instance;
}
}

浙公网安备 33010602011771号