splash_page.dart
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:wow_english/common/core/user_util.dart';
import 'package:wow_english/common/extension/string_extension.dart';
import 'package:wow_english/models/user_entity.dart';
import 'package:wow_english/route/route.dart';
import 'package:wow_english/utils/sp_util.dart';
class SplashPage extends StatelessWidget {
const SplashPage({super.key});
@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> {
Future startTime() async {
// 判断是否登录
UserEntity? userEntity = UserUtil.getUser();
if (kDebugMode) {
print('Splash读本地userEntity: $userEntity');
}
Timer(const Duration(seconds: 2), () {
if (userEntity != null) {
// todo 调一下接口判断一下有效性再往下
Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
} else {
Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
}
});
}
@override
void initState() {
super.initState();
init();
}
void init() async {
await SpUtil.preInit();
startTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'splash'.assetGif,
),
fit: BoxFit.fill)),
),
),
);
}
}