基础组件库
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.2 KiB

4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. Timer(Duration(milliseconds: 300), (){
  48. NativeUtil.notifyInitSuccess();
  49. });
  50. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  51. String versionNumber = await SharedPreferencesUtil.getStringValue(Constants.versionNumber);
  52. String currentVersionCode = packageInfo.buildNumber?.toString() ?? '';
  53. if (versionNumber == null || versionNumber == '' || versionNumber != currentVersionCode) {
  54. await _showGuideImage();
  55. SharedPreferencesUtil.setStringValue(Constants.versionNumber, currentVersionCode);
  56. }
  57. if (widget.builder != null) {
  58. Navigator.of(context).pushReplacement(CupertinoPageRoute(builder: widget.builder));
  59. } else {
  60. // Navigator.of(context).pushReplacement(
  61. // CupertinoPageRoute(builder: (context) => HomePage()));
  62. Navigator.of(context).pushReplacementNamed('/homePage');
  63. }
  64. }).catchError((err) async {
  65. // if (err.toString().contains("BaseSettingModel")) {
  66. // await showDialog(
  67. // context: context,
  68. // child: TipDialog(
  69. // content: "基本配置加载失败!请检查网络是否可用后再启动应用!",
  70. // ));
  71. // SystemNavigator.pop();
  72. // }
  73. if(showTime<3){
  74. showTime++;
  75. Fluttertoast.showToast(msg: "配置基础数据失败!请检查网络是否可用");
  76. }
  77. Timer(Duration(seconds: 5), () {
  78. validateInit();
  79. });
  80. Logger.error(err);
  81. });
  82. // } else {
  83. // ///在无网络情况下提示用户打开网络
  84. // if(showTime<3){
  85. // showTime++;
  86. // Fluttertoast.showToast(msg: "无法连接网络!请打开移动网络/连接WIFI后再尝试");
  87. // }
  88. //
  89. // Timer(Duration(seconds: 5), () {
  90. // validateInit();
  91. // });
  92. // Logger.error('未知网络,APP初始化失败');
  93. // print('unknow');
  94. // }
  95. // });
  96. }
  97. Future _showGuideImage() async {
  98. try {
  99. // 引导页
  100. AppConfigGuideModel guide = AppConfigModel.getConfig()?.guideImage;
  101. if (guide != null && guide.images.length > 0) {
  102. Dio dio = Dio();
  103. print("加载图片");
  104. List<Uint8List> guideImages = List();
  105. for (int i = 0; i < guide.images.length; i++) {
  106. Response response = await dio.get(guide.images[i], options: Options(responseType: ResponseType.bytes));
  107. if (response.statusCode == 200) {
  108. Uint8List data = Uint8List.fromList(response.data);
  109. guideImages.add(data);
  110. }
  111. }
  112. await Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GuidePage(guide, guideImages)));
  113. }
  114. } catch (e) {
  115. throw "引导图加载失败";
  116. }
  117. }
  118. @override
  119. Widget build(BuildContext context) {
  120. return Container(
  121. color: Colors.white,
  122. // child: Image.asset(
  123. // 'assets/images/launch_image/launch_image.png',
  124. // package: 'zhiying_base_widget',
  125. // fit: BoxFit.fill,
  126. // ),
  127. );
  128. }
  129. }