基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

launch_page.dart 5.3 KiB

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