diff --git a/lib/common/io/rs_http.dart b/lib/common/io/rs_http.dart index fb987bf..8dd3a3a 100644 --- a/lib/common/io/rs_http.dart +++ b/lib/common/io/rs_http.dart @@ -14,10 +14,16 @@ class RSHttp { }); } - static Future getText(String url, + static Future get(String url, {Map? headers}) async { final r = await rust_http.fetch( method: MyMethod.gets, url: url, headers: headers); + return r; + } + + static Future getText(String url, + {Map? headers}) async { + final r = await get(url, headers: headers); if (r.data == null) return ""; final str = utf8.decode(r.data!); return str; diff --git a/lib/ui/home/dialogs/md_content_dialog_ui_model.dart b/lib/ui/home/dialogs/md_content_dialog_ui_model.dart index 7029dfb..11e03da 100644 --- a/lib/ui/home/dialogs/md_content_dialog_ui_model.dart +++ b/lib/ui/home/dialogs/md_content_dialog_ui_model.dart @@ -1,5 +1,5 @@ -import 'package:dio/dio.dart'; import 'package:starcitizen_doctor/base/ui_model.dart'; +import 'package:starcitizen_doctor/common/io/rs_http.dart'; class MDContentDialogUIModel extends BaseUIModel { String title; @@ -11,9 +11,9 @@ class MDContentDialogUIModel extends BaseUIModel { @override Future loadData() async { - final r = await handleError(() => Dio().get(url)); + final r = await handleError(() => RSHttp.getText(url)); if (r == null) return; - data = r.data; + data = r; notifyListeners(); } } diff --git a/lib/ui/home/localization/localization_ui_model.dart b/lib/ui/home/localization/localization_ui_model.dart index 0341ac1..f93070e 100644 --- a/lib/ui/home/localization/localization_ui_model.dart +++ b/lib/ui/home/localization/localization_ui_model.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:io'; import 'package:archive/archive_io.dart'; -import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/api/api.dart'; @@ -10,6 +9,7 @@ import 'package:starcitizen_doctor/base/ui_model.dart'; import 'package:starcitizen_doctor/common/conf/app_conf.dart'; import 'package:starcitizen_doctor/common/conf/url_conf.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; +import 'package:starcitizen_doctor/common/io/rs_http.dart'; import 'package:starcitizen_doctor/data/sc_localization_data.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -145,7 +145,12 @@ class LocalizationUIModel extends BaseUIModel { if (!await savePath.exists()) { // download dPrint("downloading file to $savePath"); - await Dio().download(downloadUrl, savePath.absolute.path); + final r = await RSHttp.get(downloadUrl); + if (r.statusCode == 200 && r.data != null) { + await savePath.writeAsBytes(r.data!); + } else { + throw "statusCode Error : ${r.statusCode}"; + } } else { dPrint("use cache $savePath"); } diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index 249b4b0..5bd8a0b 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'dart:io'; -import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hive/hive.dart'; @@ -416,8 +415,6 @@ class ToolsUIModel extends BaseUIModel { if (r != null) { if (r == "cancel") { return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。"); - } else if (r is DioException) { - showToast(context!, "下载失败:$r"); } else { final ok = await showConfirmDialogs( context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));