简介
Flutter单例有好几种写法;
可以沿用Swift的写法;也可以用factory工厂方法;
静态变量
Intercom插件采用的直接用静态变量的方法感觉很不错,以后就这么写。
class Intercom {
/// private constructor to not allow the object creation from outside.
Intercom._();
static final Intercom _instance = Intercom._();
/// get the instance of the [Intercom].
static Intercom get instance => _instance;
/// ……
}
网友评论