|
@@ -1,3 +1,5 @@
|
|
|
+import 'dart:async';
|
|
|
+
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:vitalapp/architecture/defines.dart';
|
|
@@ -27,7 +29,7 @@ class LoginController extends FControllerBase {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- setBusy('登录中');
|
|
|
+ setBusy('正在登录');
|
|
|
// busy = true;
|
|
|
try {
|
|
|
final code = await Get.find<IAccountManager>()
|
|
@@ -54,41 +56,55 @@ class LoginController extends FControllerBase {
|
|
|
|
|
|
@override
|
|
|
void onInit() {
|
|
|
- if (Store.user.account != null) {
|
|
|
- state.account = Store.user.account!;
|
|
|
- }
|
|
|
- state.isAutoLogin = Store.user.isAutoLogin;
|
|
|
- if (Store.user.isAutoLogin) {
|
|
|
- state.password = Store.user.password ?? '';
|
|
|
- }
|
|
|
- _checkUpdate();
|
|
|
+ _loadHisState();
|
|
|
super.onInit();
|
|
|
}
|
|
|
|
|
|
- /// 记住密码状态切换
|
|
|
- void onRememberPasswordChanged(bool val) {
|
|
|
- state.isAutoLogin = val;
|
|
|
+ @override
|
|
|
+ void onReady() {
|
|
|
+ super.onReady();
|
|
|
+ _checkUpdate().then((value) {
|
|
|
+ if (value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (state.isAutoLogin && Store.user.isLogOn) {
|
|
|
+ // 勾选了“自动登录”且之前是已登录状态下,尝试自动登录
|
|
|
+ onSubmit();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- @override
|
|
|
- void onClose() {
|
|
|
- _doDispose();
|
|
|
- super.onClose();
|
|
|
+ /// 自动登录状态切换
|
|
|
+ void onAutoLoginChanged(bool val) {
|
|
|
+ state.isAutoLogin = val;
|
|
|
}
|
|
|
|
|
|
- Future<void> _checkUpdate() async {
|
|
|
+ Future<bool> _checkUpdate() async {
|
|
|
+ if (!kIsOnline) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
final result = await Get.find<IUpgradeManager>().checkNewVersionArrival();
|
|
|
if (result != null && result.isNeedUpdate) {
|
|
|
- final AppUpgradeController appUpgradeController =
|
|
|
- Get.put(AppUpgradeController());
|
|
|
+ final completer = Completer<bool>();
|
|
|
Get.dialog(
|
|
|
GetBuilder<AppUpgradeController>(
|
|
|
- builder: (_) => AppUpgradeWidget(model: result),
|
|
|
- init: appUpgradeController,
|
|
|
+ builder: (_) => AppUpgradeWidget(
|
|
|
+ model: result,
|
|
|
+ onCanceled: () {
|
|
|
+ completer.complete(false);
|
|
|
+ },
|
|
|
+ onInstallReady: () {
|
|
|
+ completer.complete(true);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ init: AppUpgradeController(),
|
|
|
),
|
|
|
barrierDismissible: false,
|
|
|
barrierColor: Colors.black.withOpacity(.4),
|
|
|
);
|
|
|
+ return completer.future;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -106,5 +122,13 @@ class LoginController extends FControllerBase {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- void _doDispose() {}
|
|
|
+ void _loadHisState() {
|
|
|
+ state.isAutoLogin = Store.user.isAutoLogin;
|
|
|
+ if (Store.user.account != null) {
|
|
|
+ state.account = Store.user.account!;
|
|
|
+ }
|
|
|
+ if (Store.user.isAutoLogin) {
|
|
|
+ state.password = Store.user.password ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|