Commit d47daa9985c44d5836b9f7772c143bfa7b715fdb
Merge remote-tracking branch 'origin/feat-wqf-payment' into xiaoyu_cocossteve
Showing
1 changed file
with
43 additions
and
12 deletions
lib/app/splash_page.dart
@@ -49,22 +49,12 @@ class _TransitionViewState extends State<TransitionView> { | @@ -49,22 +49,12 @@ class _TransitionViewState extends State<TransitionView> { | ||
49 | Log.d('Splash读本地, userEntity: $userEntity'); | 49 | Log.d('Splash读本地, userEntity: $userEntity'); |
50 | int apartInMilliseconds = 0; | 50 | int apartInMilliseconds = 0; |
51 | // 阻塞获取系统配置信息 | 51 | // 阻塞获取系统配置信息 |
52 | - await AppConfigHelper.getAppConfig(); | 52 | + AppConfigHelper.getAppConfig(); |
53 | // 调一下接口判断一下有效性再往下 | 53 | // 调一下接口判断一下有效性再往下 |
54 | if (userEntity != null && userEntity.token != null) { | 54 | if (userEntity != null && userEntity.token != null) { |
55 | String token = userEntity.token!; | 55 | String token = userEntity.token!; |
56 | DateTime startTime = DateTime.now(); | 56 | DateTime startTime = DateTime.now(); |
57 | - try { | ||
58 | - userEntity = await UserDao.getUserInfo(); | ||
59 | - Log.d('Splash在线更新, userEntity: $userEntity'); | ||
60 | - if (userEntity != null) { | ||
61 | - userEntity.token = token; | ||
62 | - Log.d('Splash重设token, userEntity: $userEntity'); | ||
63 | - UserUtil.saveUser(userEntity); | ||
64 | - } | ||
65 | - } catch (e) { | ||
66 | - e.logE(); | ||
67 | - } | 57 | + await fetchNecessaryData(token); |
68 | apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds; | 58 | apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds; |
69 | } | 59 | } |
70 | int duration = max(2000 - apartInMilliseconds, 0); | 60 | int duration = max(2000 - apartInMilliseconds, 0); |
@@ -105,6 +95,47 @@ class _TransitionViewState extends State<TransitionView> { | @@ -105,6 +95,47 @@ class _TransitionViewState extends State<TransitionView> { | ||
105 | }); | 95 | }); |
106 | } | 96 | } |
107 | 97 | ||
98 | + Future<void> fetchNecessaryData(String userToken) async { | ||
99 | + // 获取用户信息 | ||
100 | + try { | ||
101 | + UserEntity? userEntity = await UserDao.getUserInfo(); | ||
102 | + Log.d('Splash在线更新, userEntity: $userEntity'); | ||
103 | + if (userEntity != null) { | ||
104 | + userEntity.token = userToken; | ||
105 | + Log.d('Splash重设token, userEntity: $userEntity'); | ||
106 | + UserUtil.saveUser(userEntity); | ||
107 | + } | ||
108 | + } catch (e) { | ||
109 | + //异常的话弹窗提示重试 | ||
110 | + showDialog( | ||
111 | + context: context, | ||
112 | + barrierDismissible: false, | ||
113 | + builder: (BuildContext context) { | ||
114 | + return WillPopScope( | ||
115 | + onWillPop: () => Future.value(false), | ||
116 | + child: AlertDialog( | ||
117 | + title: const Text('温馨提示'), | ||
118 | + content: const Text('网络异常,请检查网络后重试'), | ||
119 | + actions: <Widget>[ | ||
120 | + TextButton( | ||
121 | + child: const Text('退出'), | ||
122 | + onPressed: () => AppConfigHelper.exitApp() | ||
123 | + ), | ||
124 | + TextButton( | ||
125 | + child: const Text('重试'), | ||
126 | + onPressed: () async { | ||
127 | + fetchNecessaryData(userToken); | ||
128 | + }, | ||
129 | + ), | ||
130 | + ], | ||
131 | + ), | ||
132 | + ); | ||
133 | + }, | ||
134 | + ); | ||
135 | + e.logE(); | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
108 | @override | 139 | @override |
109 | void initState() { | 140 | void initState() { |
110 | super.initState(); | 141 | super.initState(); |