BaseApi constructor

BaseApi()

Implementation

BaseApi() {
  client = new Dio(this._getOptions());

  client.interceptors
      .add(InterceptorsWrapper(onRequest: (RequestOptions options, RequestInterceptorHandler handler) async {
    Map<String, dynamic> headers = {};
    Map<String, String?> userDeviceMeta = await this._getUserMeta();

    String? appKey = await getStorage(key: skAppKey);
    headers.addAll(
        {"Authorization": "Bearer $appKey", "Accept": "application/json"});
    headers.addAll({"X-DMETA": jsonEncode(userDeviceMeta)});

    options.headers.addAll(headers);
    return handler.next(options);
  },
    onResponse: (Response response,
        ResponseInterceptorHandler handler) async {
      this._debugHttpLogger(response);
      return handler.next(response);
    },
    onError: (DioError e,
        ErrorInterceptorHandler handler) async {
      logResponse("${e.message}\n${e.response}");
    }
  ));
}