基础组件库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

launch_page.dart 5.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import 'dart:async';
  2. import 'dart:typed_data';
  3. import 'package:connectivity/connectivity.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/foundation.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
  9. import 'package:mobpush_plugin/mobpush_custom_message.dart';
  10. import 'package:mobpush_plugin/mobpush_notify_message.dart';
  11. import 'package:mobpush_plugin/mobpush_plugin.dart';
  12. import 'package:zhiying_base_widget/models/app_config_model.dart';
  13. import 'package:zhiying_base_widget/pages/guide_page/guide_page.dart';
  14. import 'package:zhiying_base_widget/pages/home_page/home_page.dart';
  15. import 'package:zhiying_comm/util/application.dart';
  16. import 'package:zhiying_comm/zhiying_comm.dart';
  17. import 'package:dio/dio.dart';
  18. import 'package:zhiying_base_widget/utils/contants.dart';
  19. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  20. import 'package:package_info/package_info.dart';
  21. import 'package:fluttertoast/fluttertoast.dart';
  22. // 启动页,页面初始化等操作~跟原生启动页保持一致,防止白屏问题
  23. class LaunchPage extends StatefulWidget {
  24. final WidgetBuilder builder;
  25. const LaunchPage({Key key, this.builder}) : super(key: key);
  26. @override
  27. _LaunchPageState createState() => _LaunchPageState();
  28. }
  29. class _LaunchPageState extends State<LaunchPage> with TickerProviderStateMixin {
  30. final GlobalKey navigatorKey = new GlobalKey();
  31. ///闪屏动画
  32. AnimationController animationController;
  33. int showTime=0;
  34. @override
  35. void initState() {
  36. animationController = AnimationController(vsync: this);
  37. validateInit();
  38. super.initState();
  39. }
  40. validateInit() async {
  41. // Connectivity().checkConnectivity().then((connectivityResult) async {
  42. // if (connectivityResult == ConnectivityResult.mobile || connectivityResult == ConnectivityResult.wifi) {
  43. // I am connected to a wifi network.
  44. Logger.debug('ConnectivityResult.wifi');
  45. print('ConnectivityResult.wifi');
  46. Application.init().then((_) async {
  47. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  48. String versionNumber = await SharedPreferencesUtil.getStringValue(Constants.versionNumber);
  49. String currentVersionCode = packageInfo.buildNumber?.toString() ?? '';
  50. if (versionNumber == null || versionNumber == '' || versionNumber != currentVersionCode) {
  51. await _showGuideImage();
  52. SharedPreferencesUtil.setStringValue(Constants.versionNumber, currentVersionCode);
  53. }
  54. if (widget.builder != null) {
  55. Navigator.of(context).pushReplacement(CupertinoPageRoute(builder: widget.builder));
  56. } else {
  57. // Navigator.of(context).pushReplacement(
  58. // CupertinoPageRoute(builder: (context) => HomePage()));
  59. Navigator.of(context).pushReplacementNamed('/homePage');
  60. }
  61. }).catchError((err) async {
  62. // if (err.toString().contains("BaseSettingModel")) {
  63. // await showDialog(
  64. // context: context,
  65. // child: TipDialog(
  66. // content: "基本配置加载失败!请检查网络是否可用后再启动应用!",
  67. // ));
  68. // SystemNavigator.pop();
  69. // }
  70. if(showTime<3){
  71. showTime++;
  72. Fluttertoast.showToast(msg: "配置基础数据失败!请检查网络是否可用");
  73. }
  74. Timer(Duration(seconds: 5), () {
  75. validateInit();
  76. });
  77. Logger.error(err);
  78. });
  79. // } else {
  80. // ///在无网络情况下提示用户打开网络
  81. // if(showTime<3){
  82. // showTime++;
  83. // Fluttertoast.showToast(msg: "无法连接网络!请打开移动网络/连接WIFI后再尝试");
  84. // }
  85. //
  86. // Timer(Duration(seconds: 5), () {
  87. // validateInit();
  88. // });
  89. // Logger.error('未知网络,APP初始化失败');
  90. // print('unknow');
  91. // }
  92. // });
  93. }
  94. Future _showGuideImage() async {
  95. try {
  96. // 引导页
  97. AppConfigGuideModel guide = AppConfigModel.getConfig()?.guideImage;
  98. if (guide != null && guide.images.length > 0) {
  99. Dio dio = Dio();
  100. print("加载图片");
  101. List<Uint8List> guideImages = List();
  102. for (int i = 0; i < guide.images.length; i++) {
  103. Response response = await dio.get(guide.images[i], options: Options(responseType: ResponseType.bytes));
  104. if (response.statusCode == 200) {
  105. Uint8List data = Uint8List.fromList(response.data);
  106. guideImages.add(data);
  107. }
  108. }
  109. await Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GuidePage(guide, guideImages)));
  110. }
  111. } catch (e) {
  112. throw "引导图加载失败";
  113. }
  114. }
  115. @override
  116. Widget build(BuildContext context) {
  117. return Container(
  118. color: Colors.white,
  119. child: Stack(
  120. alignment: Alignment.topCenter,
  121. children: <Widget>[
  122. Container(
  123. color: Colors.white,
  124. width: double.infinity,
  125. height: MediaQuery.of(context).size.height - MediaQuery.of(context).padding.bottom,
  126. child: Image.asset(
  127. 'assets/images/launch_image/launch_image.png',
  128. package: 'zhiying_base_widget',
  129. fit: BoxFit.cover,
  130. ),
  131. ),
  132. ],
  133. ),
  134. );
  135. }
  136. }