完成升级APP功能
This commit is contained in:
parent
309c708847
commit
b52c335c65
|
|
@ -12,6 +12,7 @@ import 'dart:io';
|
|||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'package:dio/adapter.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
|
|
@ -309,7 +310,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
],
|
||||
),
|
||||
InkWell(
|
||||
onTap: toLogin,
|
||||
onTap: () => easyThrottle('TO_GO_LOGOIN', toLogin),
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 10.h),
|
||||
decoration: BoxDecoration(
|
||||
|
|
@ -415,18 +416,54 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
setState(() => canLogin = true);
|
||||
}
|
||||
|
||||
FocusScope.of(context).requestFocus(_theFocus);
|
||||
|
||||
String userName = _userNameController.text.trim();
|
||||
String userPwd = _passwordController.text.trim();
|
||||
if (userName == '') return toMsg('请填写用户账号');
|
||||
if (userPwd == '') return toMsg('请填写密码再试');
|
||||
if (!readAgreement) return toMsg('请勾选我已阅读用户协议和隐私协议');
|
||||
|
||||
String userPwdMd5 = CommonUtils.generateMD5(userPwd);
|
||||
print('userPwdMd5=$userPwdMd5');
|
||||
EasyLoading.show(status: 'loading...');
|
||||
try {
|
||||
FocusScope.of(context).requestFocus(_theFocus);
|
||||
if (!readAgreement) {
|
||||
var resFlag = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: quickText('用户协议及隐私协议', size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)),
|
||||
content: SingleChildScrollView(
|
||||
padding: EdgeInsets.only(top: 4.h),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: '为了更好地保障您的合法权益,请您阅读并同意以下协议',
|
||||
style: TextStyle(color: Color.fromARGB(255, 137, 138, 139), fontSize: 11.sp),
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: '《用户协议》《隐式协议》', style: TextStyle(color: Colors.deepOrangeAccent, fontSize: 13.sp)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
CupertinoDialogAction(
|
||||
child: Text("取消", style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text("确定"),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
if (!resFlag!) return;
|
||||
setState(() => readAgreement = true);
|
||||
}
|
||||
|
||||
String userName = _userNameController.text.trim();
|
||||
String userPwd = _passwordController.text.trim();
|
||||
if (userName == '') return toMsg('请填写用户账号');
|
||||
if (userPwd == '') return toMsg('请填写密码再试');
|
||||
if (!readAgreement) return toMsg('请勾选我已阅读用户协议和隐私协议');
|
||||
|
||||
String userPwdMd5 = CommonUtils.generateMD5(userPwd);
|
||||
print('userPwdMd5=$userPwdMd5');
|
||||
EasyLoading.show(status: 'loading...');
|
||||
|
||||
BaseStructureResult<dynamic> resultData = await client.toLogin(UserLoginParams(userName, userPwdMd5));
|
||||
UserLogin? userData = resultData.code == 200 && resultData.data != null ? UserLogin.fromJson(resultData.data) : null;
|
||||
if (resultData.code != 200 || userData?.accessToken == null || userData?.accessToken == '') {
|
||||
|
|
@ -484,6 +521,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
return toMsg(msg ?? '登录失败,请重试');
|
||||
} finally {
|
||||
EasyLoading.dismiss();
|
||||
setState(() => canLogin = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import 'package:marking_app/common/model/user/user_info.dart';
|
|||
import 'package:marking_app/pages/reports/index.dart';
|
||||
import 'package:marking_app/provider/do_marking_provider.dart';
|
||||
import 'package:marking_app/provider/upload_file_provider.dart';
|
||||
import 'package:marking_app/routes/RouterManager.dart';
|
||||
import 'package:marking_app/utils/app_upgrade/UpdateDialog.dart';
|
||||
import 'package:marking_app/utils/app_upgrade/model/UpdateAppEvent.dart';
|
||||
import 'package:marking_app/common/model/sys/system_version.dart';
|
||||
|
|
@ -73,10 +74,11 @@ class TheMainPageState extends ConsumerState<TheMainPage> with CommonMixin {
|
|||
// 由于本项目必须登录才能浏览,所以APP升级校验在登录后
|
||||
_userListener = ref.read(userProvider.notifier).addListener((state) {
|
||||
if (state.id != '0' && state.id != '') {
|
||||
if (!showUpgrade) {
|
||||
getAppUpgrade(state);
|
||||
}
|
||||
if (!showUpgrade) getAppUpgrade(state);
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(Duration(seconds: 40), (e) {
|
||||
String? routeName = ModalRoute.of(context)?.settings.name;
|
||||
if (routeName == RouterManager.loginPath) return; // 在登录页面不更新APP
|
||||
if (!showUpgrade) getAppUpgrade(state);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,14 @@
|
|||
* @LastEditors: wangyang 1147192855@qq.com
|
||||
* @LastEditTime: 2022-08-02 15:12:21
|
||||
*/
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:install_plugin/install_plugin.dart';
|
||||
import 'package:marking_app/provider/upgrade_provider.dart';
|
||||
import 'package:marking_app/utils/app_upgrade/model/UpdateAppEvent.dart';
|
||||
import 'package:marking_app/utils/index.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:app_installer/app_installer.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
|
@ -68,12 +64,15 @@ class DownloadApk {
|
|||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("未知应用安装权限提示"),
|
||||
content: const Text("更新时若出现需要同意安装未知应用权限时,请同意"),
|
||||
title: const Text("未知应用安装权限提示",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
content: const Text("请注意:更新时若出现需要同意“安装未知应用权限”,请同意!!!"),
|
||||
actions: [
|
||||
MaterialButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
child: const Text("我已知晓", style: TextStyle(color: Colors.white)),
|
||||
child: const Text("我已知晓", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
* @LastEditors: Please set LastEditors
|
||||
* @LastEditTime: 2021-01-12 15:08:43
|
||||
*/
|
||||
import 'package:clipboard/clipboard.dart';
|
||||
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:marking_app/provider/upgrade_provider.dart';
|
||||
|
|
@ -174,7 +173,7 @@ class DownloadButton extends ConsumerWidget {
|
|||
]),
|
||||
),
|
||||
child: MaterialButton(
|
||||
onPressed: () => easyThrottle('DownloadButton_App_Upgrade', () async {
|
||||
onPressed: () => easyThrottle('DownloadButton_App_Upgrade', duration: const Duration(milliseconds: 1000), () async {
|
||||
if (deviceInfo == "android" && updateAppEvent.equipment == Equipment.android) {
|
||||
// 权限检查 判断是否有读写内存的权限
|
||||
bool flag = await UpgradePermission(updateAppEvent.deviceInfo).checkPermission(context, updateAppEvent);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
import 'package:app_installer/app_installer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marking_app/utils/index.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
|
|
@ -29,27 +28,6 @@ class UpgradePermission {
|
|||
if (status.isDenied) {
|
||||
// 普通拒绝 可以再进行提示
|
||||
|
||||
if (noExecutions == 3) {
|
||||
// 拒绝并不再提示 或者某些机型不会提示
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("提示"),
|
||||
content: const Text("若“拒绝并不再提示”或“没有弹出权限询问对话框”,再次点击同意按钮出现其他更新方式。"),
|
||||
actions: [
|
||||
MaterialButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
child: const Text("确定", style: TextStyle(color: Colors.white)),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
|
|
@ -68,14 +46,8 @@ class UpgradePermission {
|
|||
},
|
||||
);
|
||||
|
||||
// if (isPad()) {
|
||||
// // 平板无法发起权限询问 直接进入APP权限设置页面
|
||||
// await openAppSettings();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (noExecutions <= 2) return checkPermission(context, updateAppEvent, ++noExecutions);
|
||||
// 执行次数大于3次,就不再询问直接打开设置权限页面(防止某些机型不会弹起权限询问交互弹框)
|
||||
if (noExecutions < 2) return checkPermission(context, updateAppEvent, ++noExecutions);
|
||||
// 执行次数大于2次,就不再询问直接打开设置权限页面(防止某些机型不会弹起权限询问交互弹框)
|
||||
}
|
||||
|
||||
// 拒绝并不再提示
|
||||
|
|
|
|||
Loading…
Reference in New Issue