request2Get method

Future request2Get(
  1. String url,
  2. BuildContext context, {
  3. bool isShowLoading = true,
  4. String loadingContent = "请求中...",
  5. Map<String, dynamic>? queryParameters,
  6. Function? onSuccess,
  7. bool isShowToast = true,
})

Implementation

Future request2Get(String url,
    BuildContext context, {
      bool isShowLoading = true,
      String loadingContent = "请求中...",
      Map<String, dynamic>? queryParameters,
      Function? onSuccess,
      bool isShowToast = true //是否弹出异常的message
    }) async {
  if (isShowLoading) {
    updateLoading(context, loadingContent);
  }
  dynamic response = await HttpUtils.get(url, queryParameters: queryParameters);

  // debugPrint("========拦截住===mixin==1===${response is AppException}====${response.runtimeType}==");
  if (response is AppException) {
    // debugPrint("========拦截住==异常了=mixin==2=========");
    AppException err = response;
    List<int> notShowCode = co?.notShowToastCode ?? [];
    if (isShowToast && !notShowCode.contains(err.getCode())) {
      ToastUtils.toast(err.getMessage());
    }

    if (!notShowCode.contains(err.getCode())) {
      hideLoading(context, isShowLoading);
    }
    return Future.error(response);
  } else {
    hideLoading(context, isShowLoading);
  }
  return response;
}