getDio static method

Dio getDio(
  1. bool checkToken
)

Implementation

static Dio getDio(bool checkToken) {
  Dio dio = getDefaultDio();
  if (checkToken) {
    dio.interceptors
        .add(InterceptorsWrapper(onRequest: (RequestOptions options) {
      print('send request:path:${options.path},baseURL:${options.baseUrl}');
      if ((_ut ?? '').isEmpty) {
        dio.lock();
        return updateToken().then((value) {
          _ut = value.data['ut'];
          options.headers['Cookie'] = 'ut=$_ut';
          return options;
        }).whenComplete(() => dio.unlock());
      } else {
        options.headers['Cookie'] = 'ut=$_ut';
        return options;
      }
    }, onError: (DioError error) {
      return error;
    }));
  }
  return dio;
}