062f0df2
liangchengyou
feat:登录模块代码提交
|
1
|
import 'dart:async';
|
cc3b183a
liangchengyou
feat:ios启动图/logo
|
2
|
import 'dart:io';
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
3
|
import 'dart:math';
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
4
|
|
1892df31
Key
优化接口调用
|
5
|
import 'package:flutter/foundation.dart';
|
2a29701f
liangchengyou
feat:提交代码
|
6
|
import 'package:flutter/material.dart';
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
7
8
|
import 'package:flutter/services.dart';
import 'package:limiting_direction_csx/limiting_direction_csx.dart';
|
27dad3d1
吴启风
feat:集成友盟统计
|
9
|
import 'package:umeng_common_sdk/umeng_common_sdk.dart';
|
28f20da9
吴启风
feat:针对apple审核对支付...
|
10
|
import 'package:wow_english/common/core/app_config_helper.dart';
|
94342c3f
Key
feat: user util
|
11
|
import 'package:wow_english/common/core/user_util.dart';
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
12
|
import 'package:wow_english/common/extension/string_extension.dart';
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
13
|
import 'package:wow_english/common/request/config.dart';
|
e55bbdf3
Key
fixed: aliyun oss...
|
14
|
import 'package:wow_english/common/request/dao/user_dao.dart';
|
94342c3f
Key
feat: user util
|
15
|
import 'package:wow_english/models/user_entity.dart';
|
2a29701f
liangchengyou
feat:提交代码
|
16
|
import 'package:wow_english/route/route.dart';
|
0e314ad5
吴启风
feat:开屏页播放背景音乐wel...
|
17
|
import 'package:wow_english/utils/audio_player_util.dart';
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
18
|
import 'package:wow_english/utils/log_util.dart';
|
94342c3f
Key
feat: user util
|
19
|
import 'package:wow_english/utils/sp_util.dart';
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
20
|
|
2a9895f6
吴启风
feat:首次启动隐私协议弹窗
|
21
|
import '../common/core/app_consts.dart';
|
42f15f6c
吴启风
feat:模块选择持久化&模块主题...
|
22
|
import '../common/core/module_cache.dart';
|
2a9895f6
吴启风
feat:首次启动隐私协议弹窗
|
23
|
import '../common/widgets/webview_dialog.dart';
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
24
25
|
import '../common/utils/staticstring/userregister.dart';
|
a117a5a3
liangchengyou
feat:更新代码
|
26
27
|
class SplashPage extends StatelessWidget {
const SplashPage({super.key});
|
2a29701f
liangchengyou
feat:提交代码
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
@override
Widget build(BuildContext context) {
return const TransitionView();
}
}
class TransitionView extends StatefulWidget {
const TransitionView({super.key});
@override
State<StatefulWidget> createState() {
return _TransitionViewState();
}
}
class _TransitionViewState extends State<TransitionView> {
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
45
46
47
|
bool _isPrivacyDecisionInProgress = false;
bool _isInitializing = false;
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
48
|
Future startTime() async {
|
94342c3f
Key
feat: user util
|
49
50
|
// 判断是否登录
UserEntity? userEntity = UserUtil.getUser();
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
51
52
|
Log.d(
'当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode');
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
53
|
Log.d('当前API地址:${RequestConfig.baseUrl}');
|
e55bbdf3
Key
fixed: aliyun oss...
|
54
55
56
57
|
//BuildContext context = Navigator.of(context).context;
//var currentPageName = ModalRoute.of(Navigator.of(AppRouter.context))?.settings.name;
//Log.d('Splash读当前页面:$currentPageName');
Log.d('Splash读本地, userEntity: $userEntity');
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
58
|
int apartInMilliseconds = 0;
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
59
|
// 获取系统配置信息
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
60
|
AppConfigHelper.getAppConfig();
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
61
|
// 调一下接口判断一下有效性再往下
|
278208b8
吴启风
feat:1、用户访问权限调整;2...
|
62
63
|
if (userEntity != null && userEntity.token != null) {
String token = userEntity.token!;
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
64
|
DateTime startTime = DateTime.now();
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
65
|
await fetchNecessaryData(token);
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
66
|
apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds;
|
1892df31
Key
优化接口调用
|
67
|
}
|
9e14f47a
吴启风
feat:解决开场音乐前点击(带音...
|
68
|
int duration = max(1500 - apartInMilliseconds, 0);
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
69
70
|
Log.d(
'Splash getUserInfo 耗时:${apartInMilliseconds}ms, 最终duration=$duration');
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
71
|
Timer(Duration(milliseconds: duration), () {
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
72
73
74
75
76
77
78
79
80
81
82
83
84
|
pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
});
}
void _showPrivacyDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
Log.d('WQF privacy dialog onPopInvoked didPop=$didPop');
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
85
|
},
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
86
|
child: child(),
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
87
|
);
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
88
89
|
},
);
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
90
91
92
93
94
|
}
Widget child() {
if (Platform.isIOS) {
return AlertDialog(
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
95
96
97
98
|
title: const Center(
child: Text("服务条款及隐私政策"),
),
content: SizedBox(
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
99
100
|
width: MediaQuery.of(context).size.height,
height: MediaQuery.of(context).size.height,
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
101
|
child: const SingleChildScrollView(
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
102
|
child: Text(UserRegisterString.userPrivacyPolicyStr),
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
),
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: _acceptPrivacyAgreement,
child: const Text("同意并继续",
style: TextStyle(color: Color(0xFFFBB621))),
),
TextButton(
onPressed: _rejectPrivacyAgreement,
child: const Text("不同意,退出应用"),
),
],
)
],
);
|
f2cad6f6
xiaoyu
因webview显示空白没查到原因...
|
122
123
|
}
return WebviewDialog(
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
title: "服务条款及隐私政策",
webUrl: AppConsts.userPrivacyPolicyUrl,
leftButtonText: '同意并继续',
rightButtonText: '不同意,退出应用',
leftTap: _acceptPrivacyAgreement,
rightTap: _rejectPrivacyAgreement,
);
}
Future<void> _acceptPrivacyAgreement() async {
if (_isPrivacyDecisionInProgress) return;
_isPrivacyDecisionInProgress = true;
await AppConfigHelper.saveAgreementAccepted(true);
if (!mounted) return;
// 先关闭隐私政策弹窗,再进行可能耗时的 SDK 和业务初始化。
Navigator.of(context, rootNavigator: true).pop();
await _startInitialization();
_isPrivacyDecisionInProgress = false;
}
Future<void> _rejectPrivacyAgreement() async {
if (_isPrivacyDecisionInProgress) return;
_isPrivacyDecisionInProgress = true;
// 显式撤销本地授权并等待写入完成,避免退出后残留 true。
await AppConfigHelper.saveAgreementAccepted(false);
AppConfigHelper.exitApp();
}
Future<void> _startInitialization() async {
if (_isInitializing) return;
_isInitializing = true;
try {
await _initData();
} catch (error, stackTrace) {
Log.d('Splash初始化失败: $error\n$stackTrace');
_isInitializing = false;
if (mounted) {
_showInitializationErrorDialog();
}
}
}
void _showInitializationErrorDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (dialogContext) => AlertDialog(
title: const Text('温馨提示'),
content: const Text('初始化失败,请检查网络后重试'),
actions: [
const TextButton(
onPressed: AppConfigHelper.exitApp,
child: Text('退出'),
),
TextButton(
onPressed: () {
Navigator.of(dialogContext).pop();
_startInitialization();
},
child: const Text('重试'),
),
],
),
);
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
191
192
|
}
|
27dad3d1
吴启风
feat:集成友盟统计
|
193
|
///初始化数据
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
Future<void> _initData() async {
// 用户同意后,先准备 Native APM,再正式初始化 Common SDK。
if (Platform.isAndroid) {
const MethodChannel umengMethodChannel =
MethodChannel('wow_english/umeng_method_channel');
await umengMethodChannel.invokeMethod('prepareAfterPrivacyConsent');
}
// Android 插件执行 initCommon 后不会回调 MethodChannel result,返回的
// Future 永远不结束,因此这里只触发初始化,不能 await。
unawaited(UmengCommonSdk.initCommon(
"663b66b0b3362515012f4ea5", "663b66ecf32cc41105ae74b7", "official")
.catchError((error, stackTrace) {
Log.d('友盟Common SDK初始化失败: $error\n$stackTrace');
}));
await AudioPlayerUtil.getInstance()
.playAudio(AudioPlayerUtilType.welcomeToWow)
.timeout(const Duration(seconds: 10), onTimeout: () {
Log.d('欢迎音频播放超时,继续进入首页');
});
await startTime();
|
27dad3d1
吴启风
feat:集成友盟统计
|
214
215
|
}
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
216
217
218
|
Future<void> fetchNecessaryData(String userToken,
{Completer<void>? completer}) async {
completer ??= Completer<void>();
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
219
220
221
222
223
224
225
226
227
|
// 获取用户信息
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);
}
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
228
229
|
//todo 如果为null是否需要清除用户信息?
completer.complete();
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
230
|
} catch (e) {
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
231
|
debugPrint('Splash获取用户信息异常:$e');
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
232
233
234
235
236
237
|
if (!mounted) {
if (!completer.isCompleted) {
completer.complete();
}
return;
}
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
238
239
240
241
242
|
//异常的话弹窗提示重试
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
|
9e14f47a
吴启风
feat:解决开场音乐前点击(带音...
|
243
244
245
246
247
|
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
Log.d('WQF fetchNecessaryData onPopInvoked didPop=$didPop');
},
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
248
249
250
251
252
|
child: AlertDialog(
title: const Text('温馨提示'),
content: const Text('网络异常,请检查网络后重试'),
actions: <Widget>[
TextButton(
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
253
|
child: const Text('退出'),
|
c272c662
吴启风
fix: 崩溃修复
|
254
255
256
257
258
259
260
261
262
|
onPressed: () {
// 关闭对话框并退出应用
Navigator.of(context).pop();
AppConfigHelper.exitApp();
// 只有在 completer 还没有完成时才完成它
if (completer != null && !completer.isCompleted) {
completer.complete();
}
}),
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
263
264
265
|
TextButton(
child: const Text('重试'),
onPressed: () async {
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
266
267
268
|
// 关闭对话框并重试
Navigator.of(context).pop();
await fetchNecessaryData(userToken, completer: completer);
|
c272c662
吴启风
fix: 崩溃修复
|
269
|
// 不需要再次调用 completer.complete(),因为 fetchNecessaryData 内部已经处理了
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
270
271
272
273
274
275
276
277
278
|
},
),
],
),
);
},
);
e.logE();
}
|
8fec4713
吴启风
feat:启动请求失败阻塞优化
|
279
280
|
// 等待completer完成,这会阻塞后续代码的执行,直到用户做出选择
await completer.future;
|
c4458dc6
吴启风
feat:启动页必要接口增加失败重试
|
281
282
|
}
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
283
284
285
|
@override
void initState() {
super.initState();
|
089ccd5c
Key
fixed: user util ...
|
286
287
288
289
|
init();
}
void init() async {
|
0e314ad5
吴启风
feat:开屏页播放背景音乐wel...
|
290
|
changeDevice();
|
089ccd5c
Key
fixed: user util ...
|
291
|
await SpUtil.preInit();
|
42f15f6c
吴启风
feat:模块选择持久化&模块主题...
|
292
|
ModuleCache.instance.init();
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
293
294
295
296
297
298
299
300
301
|
if (AppConfigHelper.getAgreementAccepted()) {
await _startInitialization();
} else {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
_showPrivacyDialog();
}
});
}
|
cc3b183a
liangchengyou
feat:ios启动图/logo
|
302
303
304
305
306
307
|
}
void changeDevice() async {
///设置设备默认方向
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isIOS) {
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
308
309
|
await LimitingDirectionCsx.setScreenDirection(
DeviceDirectionMask.Landscape);
|
cc3b183a
liangchengyou
feat:ios启动图/logo
|
310
|
} else {
|
6c23b545
吴启风
fix: 修复友盟隐私合规初始化时机
|
311
312
|
await SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
cc3b183a
liangchengyou
feat:ios启动图/logo
|
313
|
}
|
1f01c7f0
吴启风
fix:修复部分设备(比如华为p3...
|
314
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
315
316
|
}
|
2a29701f
liangchengyou
feat:提交代码
|
317
318
319
|
@override
Widget build(BuildContext context) {
return Scaffold(
|
2a29701f
liangchengyou
feat:提交代码
|
320
|
body: Center(
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
321
322
323
324
|
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
325
|
'splash'.assetGif,
|
062f0df2
liangchengyou
feat:登录模块代码提交
|
326
|
),
|
94342c3f
Key
feat: user util
|
327
|
fit: BoxFit.fill)),
|
2a29701f
liangchengyou
feat:提交代码
|
328
329
330
331
|
),
),
);
}
|
056970d8
Key
feat: api
|
332
|
}
|