Browse Source

fix 0016702: 【APP】【登录】已勾选自动登录,每次打开app,都不会自动登录,都停留在登录页面

Melon 1 year ago
parent
commit
5ea74a4276

+ 1 - 1
lib/architecture/utils/prompt_box.dart

@@ -19,7 +19,7 @@ class PromptBox {
 
   static void init() {
     EasyLoading.instance
-      ..displayDuration = const Duration(milliseconds: 2000)
+      ..displayDuration = const Duration(milliseconds: 2500)
       ..indicatorType = EasyLoadingIndicatorType.ring
       ..loadingStyle = EasyLoadingStyle.custom
       ..indicatorSize = 35.0

+ 46 - 22
lib/pages/login/controller.dart

@@ -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 ?? '';
+    }
+  }
 }

+ 1 - 1
lib/pages/login/view.dart

@@ -113,7 +113,7 @@ class LoginPage extends GetView<LoginController> {
                               padding:
                                   const EdgeInsets.symmetric(horizontal: 4.0),
                               value: controller.state.isAutoLogin,
-                              onChanged: controller.onRememberPasswordChanged,
+                              onChanged: controller.onAutoLoginChanged,
                               mainAxisAlignment: MainAxisAlignment.start,
                             ),
                           )

+ 2 - 5
lib/pages/splash/controller.dart

@@ -11,11 +11,8 @@ class SplashController extends FControllerBase {
 
   /// 跳转路由
   void onRouteTo() async {
-    if (Store.user.isLogOn) {
-      Get.offAllNamed("/");
-    } else {
-      Get.offAllNamed("/login");
-    }
+    /// 重启后,统一到登录页
+    Get.offAllNamed("/login");
   }
 
   /// 加载数据