提交 9375368b authored 作者: 张国庆's avatar 张国庆

fix:增加下载网络状态判断

上级 5d26d715
import 'package:apk_update/utils/dio_update_util.dart';
import 'package:apk_update/utils/utils.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'apk_update_platform_interface.dart';
......@@ -77,9 +77,8 @@ class ApkUpdate {
debugPrint("===== installApk");
ApkUpdatePlatform.instance.installApk(path);
},
downloadApk: (String? path, String? apkPath) {
final dio = Dio();
dio
downloadApk: (String? path, String? apkPath) async {
DioUpdateUtil.getDio()
.get("${paramsOSS?['baseUrl']}$generateByExt",
queryParameters: {
"extension": "apk",
......
import 'package:connectivity_plus/connectivity_plus.dart';
export 'package:connectivity_plus/connectivity_plus.dart';
final Connectivity connectivity = Connectivity();
\ No newline at end of file
import 'package:dio/dio.dart';
export 'package:dio/dio.dart';
class DioUpdateUtil {
// dio 单例对象
static final Dio _dio = Dio();
static Dio getDio() {
return _dio;
}
}
......@@ -3,13 +3,13 @@ import 'dart:convert';
import 'package:apk_update/utils/connectivity_util.dart';
import 'package:apk_update/utils/toast_util.dart';
import 'package:apk_update/widget/update_dialog.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dio_update_util.dart';
// 获取版本号
const String getSystemVersionByNumber =
"/user-service/system/version/getSystemVersionByNumber";
......@@ -44,7 +44,7 @@ void checkVersion(
}
try {
final Response response = await Dio().request(
final Response response = await DioUpdateUtil.getDio().request(
url,
options: Options(method: method.value, headers: header),
queryParameters: params,
......
import 'dart:async';
import 'dart:io';
import 'package:apk_update/utils/connectivity_util.dart';
import 'package:apk_update/utils/image_utils.dart';
import 'package:apk_update/utils/toast_util.dart';
import 'package:apk_update/utils/utils.dart';
import 'package:dio/dio.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
......@@ -93,11 +95,21 @@ class _UpdateDialogState extends State<UpdateDialog> {
children: <Widget>[
_btn(
title: '立即更新',
onTap: () {
onTap: () async {
if (Platform.isIOS) {
Navigator.pop(context);
widget.jumpAppStore?.call();
} else {
// 判断网络是否连接
var resList = await connectivity
.checkConnectivity();
if (resList.isNotEmpty &&
resList[0] ==
ConnectivityResult.none) {
ToastUtil.showToast("网络异常,请检查网络");
return;
}
setState(() {
_isDownload = true;
});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论