diff --git a/lib/app/splash_page.dart b/lib/app/splash_page.dart index 8162f4c..a20b7a7 100644 --- a/lib/app/splash_page.dart +++ b/lib/app/splash_page.dart @@ -49,22 +49,12 @@ class _TransitionViewState extends State { Log.d('Splash读本地, userEntity: $userEntity'); int apartInMilliseconds = 0; // 阻塞获取系统配置信息 - await AppConfigHelper.getAppConfig(); + AppConfigHelper.getAppConfig(); // 调一下接口判断一下有效性再往下 if (userEntity != null && userEntity.token != null) { String token = userEntity.token!; DateTime startTime = DateTime.now(); - try { - userEntity = await UserDao.getUserInfo(); - Log.d('Splash在线更新, userEntity: $userEntity'); - if (userEntity != null) { - userEntity.token = token; - Log.d('Splash重设token, userEntity: $userEntity'); - UserUtil.saveUser(userEntity); - } - } catch (e) { - e.logE(); - } + await fetchNecessaryData(token); apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds; } int duration = max(2000 - apartInMilliseconds, 0); @@ -105,6 +95,47 @@ class _TransitionViewState extends State { }); } + Future fetchNecessaryData(String userToken) async { + // 获取用户信息 + try { + UserEntity? userEntity = await UserDao.getUserInfo(); + Log.d('Splash在线更新, userEntity: $userEntity'); + if (userEntity != null) { + userEntity.token = userToken; + Log.d('Splash重设token, userEntity: $userEntity'); + UserUtil.saveUser(userEntity); + } + } catch (e) { + //异常的话弹窗提示重试 + showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return WillPopScope( + onWillPop: () => Future.value(false), + child: AlertDialog( + title: const Text('温馨提示'), + content: const Text('网络异常,请检查网络后重试'), + actions: [ + TextButton( + child: const Text('退出'), + onPressed: () => AppConfigHelper.exitApp() + ), + TextButton( + child: const Text('重试'), + onPressed: () async { + fetchNecessaryData(userToken); + }, + ), + ], + ), + ); + }, + ); + e.logE(); + } + } + @override void initState() { super.initState();