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

110 lines
4.2 KiB

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