基础组件库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

159 righe
5.8 KiB

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