Dart单例

Dart 单例

dart 中下划线 _ 开头,表示私有的方法或者属性

class NetRequest {

  Dio dio;
  /**
   * 实例化对象
   */
  static NetRequest requestUtil =  NetRequest._();
  /**
   * 私有构造函数
   */
  NetRequest._(){
    dio = new Dio();
    dio.options.connectTimeout = TIMEOUT;
    dio.options.receiveTimeout = TIMEOUT;
  }

  static NetRequest getInstance() {
    return requestUtil;
  }
}

你可能感兴趣的:(Android,dart,single)