Blame view

lib/app/splash_page.dart 2.25 KB
062f0df2   liangchengyou   feat:登录模块代码提交
1
  import 'dart:async';
cc3b183a   liangchengyou   feat:ios启动图/logo
2
  import 'dart:io';
062f0df2   liangchengyou   feat:登录模块代码提交
3
  
1892df31   Key   优化接口调用
4
  import 'package:flutter/foundation.dart';
2a29701f   liangchengyou   feat:提交代码
5
  import 'package:flutter/material.dart';
94342c3f   Key   feat: user util
6
  import 'package:wow_english/common/core/user_util.dart';
062f0df2   liangchengyou   feat:登录模块代码提交
7
  import 'package:wow_english/common/extension/string_extension.dart';
94342c3f   Key   feat: user util
8
  import 'package:wow_english/models/user_entity.dart';
2a29701f   liangchengyou   feat:提交代码
9
  import 'package:wow_english/route/route.dart';
94342c3f   Key   feat: user util
10
  import 'package:wow_english/utils/sp_util.dart';
cc3b183a   liangchengyou   feat:ios启动图/logo
11
12
  import 'package:flutter/services.dart';
  import 'package:limiting_direction_csx/limiting_direction_csx.dart';
062f0df2   liangchengyou   feat:登录模块代码提交
13
  
a117a5a3   liangchengyou   feat:更新代码
14
15
  class SplashPage extends StatelessWidget {
    const SplashPage({super.key});
2a29701f   liangchengyou   feat:提交代码
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  
    @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> {
062f0df2   liangchengyou   feat:登录模块代码提交
33
    Future startTime() async {
94342c3f   Key   feat: user util
34
35
      // 判断是否登录
      UserEntity? userEntity = UserUtil.getUser();
1892df31   Key   优化接口调用
36
      if (kDebugMode) {
aa4e28be   Key   removed: cache_bl...
37
        print('Splash读本地userEntity: $userEntity');
1892df31   Key   优化接口调用
38
      }
94342c3f   Key   feat: user util
39
      Timer(const Duration(seconds: 2), () {
aa4e28be   Key   removed: cache_bl...
40
41
        if (userEntity != null) {
          // todo 调一下接口判断一下有效性再往下
08a0f5a8   liangchengyou   feat:路由方式更新
42
          pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
062f0df2   liangchengyou   feat:登录模块代码提交
43
        } else {
08a0f5a8   liangchengyou   feat:路由方式更新
44
          pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
062f0df2   liangchengyou   feat:登录模块代码提交
45
46
47
48
49
50
51
        }
      });
    }
  
    @override
    void initState() {
      super.initState();
089ccd5c   Key   fixed: user util ...
52
53
54
55
56
      init();
    }
  
    void init() async {
      await SpUtil.preInit();
062f0df2   liangchengyou   feat:登录模块代码提交
57
      startTime();
cc3b183a   liangchengyou   feat:ios启动图/logo
58
59
60
61
62
63
64
65
66
67
68
      changeDevice();
    }
  
    void changeDevice() async {
      ///设置设备默认方向
      WidgetsFlutterBinding.ensureInitialized();
      if (Platform.isIOS) {
        await LimitingDirectionCsx.setScreenDirection(DeviceDirectionMask.Landscape);
      } else {
        await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
      }
062f0df2   liangchengyou   feat:登录模块代码提交
69
70
    }
  
2a29701f   liangchengyou   feat:提交代码
71
72
73
    @override
    Widget build(BuildContext context) {
      return Scaffold(
2a29701f   liangchengyou   feat:提交代码
74
        body: Center(
062f0df2   liangchengyou   feat:登录模块代码提交
75
76
77
78
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
79
                      'splash'.assetGif,
062f0df2   liangchengyou   feat:登录模块代码提交
80
                    ),
94342c3f   Key   feat: user util
81
                    fit: BoxFit.fill)),
2a29701f   liangchengyou   feat:提交代码
82
83
84
85
          ),
        ),
      );
    }
056970d8   Key   feat: api
86
  }