mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 06:33:43 +08:00
更换 Dio -> RSHttp
This commit is contained in:
parent
9ee02e9312
commit
a0dceb27d9
@ -14,10 +14,16 @@ class RSHttp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> getText(String url,
|
static Future<RustHttpResponse> get(String url,
|
||||||
{Map<String, String>? headers}) async {
|
{Map<String, String>? headers}) async {
|
||||||
final r = await rust_http.fetch(
|
final r = await rust_http.fetch(
|
||||||
method: MyMethod.gets, url: url, headers: headers);
|
method: MyMethod.gets, url: url, headers: headers);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> getText(String url,
|
||||||
|
{Map<String, String>? headers}) async {
|
||||||
|
final r = await get(url, headers: headers);
|
||||||
if (r.data == null) return "";
|
if (r.data == null) return "";
|
||||||
final str = utf8.decode(r.data!);
|
final str = utf8.decode(r.data!);
|
||||||
return str;
|
return str;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||||
|
|
||||||
class MDContentDialogUIModel extends BaseUIModel {
|
class MDContentDialogUIModel extends BaseUIModel {
|
||||||
String title;
|
String title;
|
||||||
@ -11,9 +11,9 @@ class MDContentDialogUIModel extends BaseUIModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future loadData() async {
|
Future loadData() async {
|
||||||
final r = await handleError(() => Dio().get(url));
|
final r = await handleError(() => RSHttp.getText(url));
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
data = r.data;
|
data = r;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:archive/archive_io.dart';
|
import 'package:archive/archive_io.dart';
|
||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||||
import 'package:starcitizen_doctor/api/api.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/app_conf.dart';
|
||||||
import 'package:starcitizen_doctor/common/conf/url_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/helper/system_helper.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
@ -145,7 +145,12 @@ class LocalizationUIModel extends BaseUIModel {
|
|||||||
if (!await savePath.exists()) {
|
if (!await savePath.exists()) {
|
||||||
// download
|
// download
|
||||||
dPrint("downloading file to $savePath");
|
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 {
|
} else {
|
||||||
dPrint("use cache $savePath");
|
dPrint("use cache $savePath");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
@ -416,8 +415,6 @@ class ToolsUIModel extends BaseUIModel {
|
|||||||
if (r != null) {
|
if (r != null) {
|
||||||
if (r == "cancel") {
|
if (r == "cancel") {
|
||||||
return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||||
} else if (r is DioException) {
|
|
||||||
showToast(context!, "下载失败:$r");
|
|
||||||
} else {
|
} else {
|
||||||
final ok = await showConfirmDialogs(
|
final ok = await showConfirmDialogs(
|
||||||
context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));
|
context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));
|
||||||
|
Loading…
Reference in New Issue
Block a user