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

115 lines
4.3 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. NativeUtil.notifyInitSuccess();
  39. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  40. String versionNumber =
  41. await SharedPreferencesUtil.getStringValue(Constants.versionNumber);
  42. String currentVersionCode =
  43. packageInfo.buildNumber?.toString() ?? '';
  44. if (versionNumber == null || versionNumber == '' || versionNumber != currentVersionCode) {
  45. await _showGuideImage();
  46. SharedPreferencesUtil.setStringValue(Constants.versionNumber, currentVersionCode);
  47. }
  48. if (widget.builder != null) {
  49. Navigator.of(context).pushReplacement(CupertinoPageRoute(builder: widget.builder));
  50. } else {
  51. // Navigator.of(context).pushReplacement(
  52. // CupertinoPageRoute(builder: (context) => HomePage()));
  53. Navigator.of(context).pushReplacementNamed('/homePage');
  54. }
  55. }).catchError((err) async {
  56. if(err.toString().contains("BaseSettingModel")){
  57. await showDialog(context: context,child: TipDialog(content: "基本配置加载失败!请检查网络是否可用后再启动应用!",));
  58. SystemNavigator.pop();
  59. }
  60. Logger.error(err);
  61. });
  62. } else {
  63. ///在无网络情况下提示用户打开网络
  64. await showDialog(context: context,child: TipDialog(content: "无法连接网络!请打开移动网络/连接WIFI后再尝试",));
  65. Logger.error('未知网络,APP初始化失败');
  66. print('unknow');
  67. SystemNavigator.pop();
  68. }
  69. });
  70. super.initState();
  71. }
  72. Future _showGuideImage() async {
  73. // 引导页
  74. AppConfigGuideModel guide = AppConfigModel.getConfig()?.guideImage;
  75. if (guide != null && guide.images.length > 0) {
  76. Dio dio = Dio();
  77. List<Uint8List> guideImages = List();
  78. for (int i = 0; i < guide.images.length; i++) {
  79. Response response = await dio.get(guide.images[i], options: Options(responseType: ResponseType.bytes));
  80. if (response.statusCode == 200) {
  81. Uint8List data = Uint8List.fromList(response.data);
  82. guideImages.add(data);
  83. }
  84. }
  85. await Navigator.of(context).push(
  86. CupertinoPageRoute(builder: (context) => GuidePage(guide, guideImages)));
  87. }
  88. }
  89. @override
  90. Widget build(BuildContext context) {
  91. return Container(
  92. color: Colors.white,
  93. child: Image.asset(
  94. 'assets/images/launch_image/launch_image.png',
  95. package: 'zhiying_base_widget',
  96. fit: BoxFit.fill,
  97. ),
  98. );
  99. }
  100. }