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

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