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

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