基础组件库
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

175 строки
6.3 KiB

  1. import 'dart:convert';
  2. import 'dart:async';
  3. import 'dart:io';
  4. import 'dart:typed_data';
  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/global_dialog/policy_dialog/policy_dialog.dart';
  13. import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
  14. import 'package:mobpush_plugin/mobpush_custom_message.dart';
  15. import 'package:mobpush_plugin/mobpush_notify_message.dart';
  16. import 'package:mobpush_plugin/mobpush_plugin.dart';
  17. import 'package:zhiying_base_widget/models/app_config_model.dart';
  18. import 'package:zhiying_base_widget/pages/guide_page/guide_page.dart';
  19. import 'package:zhiying_base_widget/pages/home_page/home_page.dart';
  20. import 'package:zhiying_comm/util/application.dart';
  21. import 'package:zhiying_comm/zhiying_comm.dart';
  22. import 'package:dio/dio.dart';
  23. import 'package:zhiying_base_widget/utils/contants.dart';
  24. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  25. import 'package:package_info/package_info.dart';
  26. import 'package:fluttertoast/fluttertoast.dart';
  27. import 'package:zhiying_comm/util/update/app_update_util.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. ///检查是否覆盖安装
  50. //取masterId
  51. String lasterMasterId = await SharedPreferencesUtil.getStringValue(Constants.masterId, defaultVal: "1");
  52. Map setting = await NativeUtil.getSetting();
  53. String masterId = setting['master_id'];
  54. if (lasterMasterId != "1") {
  55. if (masterId != lasterMasterId) {
  56. await SharedPreferencesUtil.clean();
  57. }
  58. }
  59. SharedPreferencesUtil.setStringValue(Constants.masterId, masterId);
  60. Application.init().then((_) async {
  61. ///初始化广告SDK
  62. await AdvertisingUtils.init();
  63. ///引导页
  64. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  65. String versionNumber = await SharedPreferencesUtil.getStringValue(Constants.versionNumber);
  66. String currentVersionCode = packageInfo.buildNumber?.toString() ?? '';
  67. if (versionNumber == null || versionNumber == '' || versionNumber != currentVersionCode) {
  68. await _showGuideImage();
  69. SharedPreferencesUtil.setStringValue(Constants.versionNumber, currentVersionCode);
  70. }
  71. if (widget.builder != null) {
  72. Navigator.of(context).pushReplacement(CupertinoPageRoute(builder: widget.builder));
  73. } else {
  74. // Navigator.of(context).pushReplacement(
  75. // CupertinoPageRoute(builder: (context) => HomePage()));
  76. print("打开首页");
  77. Navigator.of(context).pushReplacementNamed('/homePage');
  78. }
  79. }).catchError((err, s) async {
  80. print(s);
  81. // if (err.toString().contains("BaseSettingModel")) {
  82. // await showDialog(
  83. // context: context,
  84. // child: TipDialog(
  85. // content: "基本配置加载失败!请检查网络是否可用后再启动应用!",
  86. // ));
  87. // SystemNavigator.pop();
  88. // }
  89. if (showTime < 3) {
  90. showTime++;
  91. Fluttertoast.showToast(msg: "配置基础数据失败!请检查网络是否可用");
  92. }
  93. Timer(Duration(seconds: 5), () async {
  94. await SharedPreferencesUtil.setStringValue(GlobalConfig.GUIDE, "1");
  95. await SharedPreferencesUtil.setStringValue(GlobalConfig.MAIN_CONFIG, "1");
  96. validateInit();
  97. });
  98. Logger.error(err);
  99. });
  100. // } else {
  101. // ///在无网络情况下提示用户打开网络
  102. // if(showTime<3){
  103. // showTime++;
  104. // Fluttertoast.showToast(msg: "无法连接网络!请打开移动网络/连接WIFI后再尝试");
  105. // }
  106. //
  107. // Timer(Duration(seconds: 5), () {
  108. // validateInit();
  109. // });
  110. // Logger.error('未知网络,APP初始化失败');
  111. // print('unknow');
  112. // }
  113. // });
  114. }
  115. Future _showGuideImage() async {
  116. try {
  117. // 引导页
  118. AppConfigModel guide = AppConfigModel.getConfig();
  119. if (guide != null && guide.guideData.guideCss.length > 0) {
  120. Dio dio = Dio();
  121. print("加载图片");
  122. List<Uint8List> guideImages = List();
  123. List<Uint8List> bgImages = List();
  124. for (int i = 0; i < guide.guideData.guideCss.length; i++) {
  125. try {
  126. Response response = await dio.get(guide.guideData.guideCss[i].contentImage, options: Options(responseType: ResponseType.bytes));
  127. if (response.statusCode == 200) {
  128. Uint8List data = Uint8List.fromList(response.data);
  129. guideImages.add(data);
  130. }
  131. } catch (e, s) {
  132. guideImages.add(null);
  133. }
  134. try {
  135. Response response = await dio.get(guide.guideData.guideCss[i].bgImage, options: Options(responseType: ResponseType.bytes));
  136. if (response.statusCode == 200) {
  137. Uint8List data = Uint8List.fromList(response.data);
  138. bgImages.add(data);
  139. }
  140. } catch (e, s) {
  141. bgImages.add(null);
  142. }
  143. }
  144. NativeUtil.notifyInitSuccess();
  145. await Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GuidePage(guide.guideData, guideImages, bgImages)));
  146. }
  147. } catch (e) {
  148. throw "引导图加载失败";
  149. }
  150. }
  151. @override
  152. Widget build(BuildContext context) {
  153. return Container(
  154. color: Colors.white,
  155. );
  156. }
  157. }