request2Download method

Future request2Download(
  1. String url,
  2. String savePath,
  3. BuildContext context, {
  4. bool isShowLoading = true,
  5. String loadingContent = "请求中...",
  6. Map<String, dynamic>? queryParameters,
  7. bool isShowToast = true,
  8. bool backDismissible = true,
  9. ProgressCallback? onReceiveProgress,
})

Implementation

Future request2Download(String url, String savePath, BuildContext context,
    {bool isShowLoading = true,
      String loadingContent = "请求中...",
      Map<String, dynamic>? queryParameters,
      bool isShowToast = true, //是否弹出异常的message
      bool backDismissible = true, //点返回是否消失
      ProgressCallback? onReceiveProgress}) async {
  if (isShowLoading) {
    updateLoading(context, loadingContent, backDismissible: backDismissible);
  }
  dynamic response = await HttpUtils.downloadFile(url, savePath, onReceiveProgress: onReceiveProgress);

  // 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;
}