init method

Future<HttpService> init({
  1. int timeout = 10,
})

初始化 timeout 请求超时时间

Implementation

Future<HttpService> init({int timeout = 10}) async {
  BaseOptions options = BaseOptions(
      connectTimeout: Duration(seconds: timeout),
      receiveTimeout: Duration(seconds: timeout),
      sendTimeout: Duration(seconds: timeout),
      contentType: 'application/json; charset=utf-8',
      responseType: ResponseType.json,
      headers: {
        'Accept': 'application/json',
      });
  // 初始化dio
  _dio = Dio(options);
  // Log拦截器
  dio.interceptors.add(
    PrettyDioLogger(
      showRequest: false,
      showResponse: true,
      responseHeader: true,
      responseBody: true,
      showError: true,
      logPrint: Logger.network,
    ),
  );
  // 自定义添加拦截器
  _dio.interceptors.add(DioInterceptors());
  return this;
}