Blame view

lib/app/splash_page.dart 4.7 KB
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';
28f20da9   吴启风   feat:针对apple审核对支付...
9
  import 'package:wow_english/common/core/app_config_helper.dart';
94342c3f   Key   feat: user util
10
  import 'package:wow_english/common/core/user_util.dart';
062f0df2   liangchengyou   feat:登录模块代码提交
11
  import 'package:wow_english/common/extension/string_extension.dart';
a4d8eaa2   Key   feat: 登录时账户有效性校验
12
  import 'package:wow_english/common/request/config.dart';
e55bbdf3   Key   fixed: aliyun oss...
13
  import 'package:wow_english/common/request/dao/user_dao.dart';
94342c3f   Key   feat: user util
14
  import 'package:wow_english/models/user_entity.dart';
2a29701f   liangchengyou   feat:提交代码
15
  import 'package:wow_english/route/route.dart';
a4d8eaa2   Key   feat: 登录时账户有效性校验
16
  import 'package:wow_english/utils/log_util.dart';
94342c3f   Key   feat: user util
17
  import 'package:wow_english/utils/sp_util.dart';
062f0df2   liangchengyou   feat:登录模块代码提交
18
  
2a9895f6   吴启风   feat:首次启动隐私协议弹窗
19
20
21
  import '../common/core/app_consts.dart';
  import '../common/widgets/webview_dialog.dart';
  
a117a5a3   liangchengyou   feat:更新代码
22
23
  class SplashPage extends StatelessWidget {
    const SplashPage({super.key});
2a29701f   liangchengyou   feat:提交代码
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  
    @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:登录模块代码提交
41
    Future startTime() async {
94342c3f   Key   feat: user util
42
43
      // 判断是否登录
      UserEntity? userEntity = UserUtil.getUser();
a4d8eaa2   Key   feat: 登录时账户有效性校验
44
45
      Log.d('当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode');
      Log.d('当前API地址:${RequestConfig.baseUrl}');
e55bbdf3   Key   fixed: aliyun oss...
46
47
48
49
      //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: 登录时账户有效性校验
50
      int apartInMilliseconds = 0;
28f20da9   吴启风   feat:针对apple审核对支付...
51
52
      // 阻塞获取系统配置信息
      await AppConfigHelper.getAppConfig();
a4d8eaa2   Key   feat: 登录时账户有效性校验
53
      // 调一下接口判断一下有效性再往下
278208b8   吴启风   feat:1、用户访问权限调整;2...
54
55
      if (userEntity != null && userEntity.token != null) {
        String token = userEntity.token!;
a4d8eaa2   Key   feat: 登录时账户有效性校验
56
        DateTime startTime = DateTime.now();
e55bbdf3   Key   fixed: aliyun oss...
57
58
59
60
61
62
63
64
65
66
67
        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();
        }
a4d8eaa2   Key   feat: 登录时账户有效性校验
68
        apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds;
1892df31   Key   优化接口调用
69
      }
a4d8eaa2   Key   feat: 登录时账户有效性校验
70
      int duration = max(2000 - apartInMilliseconds, 0);
e55bbdf3   Key   fixed: aliyun oss...
71
      Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms, 最终duration=$duration');
a4d8eaa2   Key   feat: 登录时账户有效性校验
72
      Timer(Duration(milliseconds: duration), () {
210d15e0   Key   fixed: 账户注销接口
73
        /*if (userEntity != null) {
08a0f5a8   liangchengyou   feat:路由方式更新
74
          pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
062f0df2   liangchengyou   feat:登录模块代码提交
75
        } else {
08a0f5a8   liangchengyou   feat:路由方式更新
76
          pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
210d15e0   Key   fixed: 账户注销接口
77
        }*/
2a9895f6   吴启风   feat:首次启动隐私协议弹窗
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
        bool isAggreementAccepted = AppConfigHelper.getAgreementAccepted();
        if (isAggreementAccepted) {
          pushNamedAndRemoveUntil(AppRouteName.moduleSelect, (route) => false);
        } else {
          showDialog(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
              return WillPopScope(
                onWillPop: () => Future.value(false),
                child: WebviewDialog(
                  title: "服务条款及隐私政策",
                  webUrl: AppConsts.userPrivacyPolicyUrl,
                  leftTap: () {
                    AppConfigHelper.saveAgreementAccepted(true);
                    pushNamedAndRemoveUntil(
                        AppRouteName.moduleSelect, (route) => false);
                  },
                  rightTap: () {
                    // 退出应用
                    SystemNavigator.pop();
                  },
                ),
              );
            },
          );
        }
062f0df2   liangchengyou   feat:登录模块代码提交
105
106
107
108
109
110
      });
    }
  
    @override
    void initState() {
      super.initState();
089ccd5c   Key   fixed: user util ...
111
112
113
114
115
      init();
    }
  
    void init() async {
      await SpUtil.preInit();
062f0df2   liangchengyou   feat:登录模块代码提交
116
      startTime();
cc3b183a   liangchengyou   feat:ios启动图/logo
117
118
119
120
121
122
123
124
125
      changeDevice();
    }
  
    void changeDevice() async {
      ///设置设备默认方向
      WidgetsFlutterBinding.ensureInitialized();
      if (Platform.isIOS) {
        await LimitingDirectionCsx.setScreenDirection(DeviceDirectionMask.Landscape);
      } else {
a4d8eaa2   Key   feat: 登录时账户有效性校验
126
        await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
cc3b183a   liangchengyou   feat:ios启动图/logo
127
      }
062f0df2   liangchengyou   feat:登录模块代码提交
128
129
    }
  
2a29701f   liangchengyou   feat:提交代码
130
131
132
    @override
    Widget build(BuildContext context) {
      return Scaffold(
2a29701f   liangchengyou   feat:提交代码
133
        body: Center(
062f0df2   liangchengyou   feat:登录模块代码提交
134
135
136
137
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
138
                      'splash'.assetGif,
062f0df2   liangchengyou   feat:登录模块代码提交
139
                    ),
94342c3f   Key   feat: user util
140
                    fit: BoxFit.fill)),
2a29701f   liangchengyou   feat:提交代码
141
142
143
144
          ),
        ),
      );
    }
056970d8   Key   feat: api
145
  }