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

launch_page.dart 1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import 'package:connectivity/connectivity.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/pages/home_page/home_page.dart';
  4. import 'package:zhiying_comm/util/application.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. // 启动页,页面初始化等操作~跟原生启动页保持一致,防止白屏问题
  7. class LaunchPage extends StatefulWidget {
  8. final WidgetBuilder builder;
  9. const LaunchPage({Key key, this.builder}) : super(key: key);
  10. @override
  11. _LaunchPageState createState() => _LaunchPageState();
  12. }
  13. class _LaunchPageState extends State<LaunchPage> {
  14. @override
  15. void initState() {
  16. Connectivity().checkConnectivity().then((connectivityResult) {
  17. if (connectivityResult == ConnectivityResult.mobile ||
  18. connectivityResult == ConnectivityResult.wifi) {
  19. // I am connected to a wifi network.
  20. Logger.debug('ConnectivityResult.wifi');
  21. print('ConnectivityResult.wifi');
  22. Application.init().then((_) {
  23. if (widget.builder != null) {
  24. Navigator.of(context)
  25. .pushReplacement(MaterialPageRoute(builder: widget.builder));
  26. } else {
  27. Navigator.of(context).pushReplacement(
  28. MaterialPageRoute(builder: (context) => HomePage()));
  29. }
  30. }).catchError((err) {
  31. Logger.error(err);
  32. });
  33. } else {
  34. Logger.error('未知网络,APP初始化失败');
  35. print('unknow');
  36. }
  37. });
  38. super.initState();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Image.asset(
  43. 'assets/images/launch_image/launch_image.png',
  44. package: 'zhiying_base_widget',
  45. );
  46. }
  47. }