requestHttp function

Future<void> requestHttp(
  1. RequestType type,
  2. Http dio,
  3. String url, {
  4. Map<String, dynamic>? p,
  5. bool isShowDialog = false,
  6. bool dialogAllClear = false,
  7. bool isShowError = true,
  8. bool isShowHint = true,
  9. bool disposeJson = false,
  10. bool? isFromData,
  11. Function? notLogin,
  12. required RequestSucceed succeed,
  13. RequestFailure? failure,
})

Implementation

Future<void> requestHttp(
  RequestType type,
  Http dio,
  String url, {
  Map<String, dynamic>? p,
  bool isShowDialog = false,
  bool dialogAllClear = false,
  bool isShowError = true,
  bool isShowHint = true,
  bool disposeJson = false,
  bool? isFromData,
  Function? notLogin,
  required RequestSucceed succeed,
  RequestFailure? failure,
}) async {
  Response response;
  dio.options.extra.update(keyShowDialog, (item) => isShowDialog,
      ifAbsent: () => isShowDialog);
  dio.options.extra.update(keyDialogAllClear, (item) => dialogAllClear,
      ifAbsent: () => dialogAllClear);
  dio.options.extra
      .update(keyShowError, (item) => isShowError, ifAbsent: () => isShowError);
  dio.options.extra
      .update(keyShowHint, (item) => isShowHint, ifAbsent: () => isShowHint);
  dio.options.extra.update(keyDisposeJson, (item) => disposeJson,
      ifAbsent: () => disposeJson);
  try {
    switch (type) {
      case RequestType.Get:
        response = await dio.get(url, queryParameters: p);
        break;
      case RequestType.Post:
        var data = isFromData ?? postDataIsFromData
            ? (p != null ? FormData.fromMap(p) : null)
            : p;
        response = await dio.post(url, data: data);
        break;
    }
    succeed(response);
  } on DioError catch (e) {
//    LogUtil.printLog("UnAuthorizedException");
    if (e.error is UnAuthorizedException) {
      if (notLogin != null) notLogin();
    } else {
      LogUtil.printLog("error");
      if (failure != null) failure(e);
    }
  }
}