main.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import 'dart:async';
  2. import 'package:fis_lib_business_components/index.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:fis_common/logger/logger.dart';
  6. import 'package:flutter_easyloading/flutter_easyloading.dart';
  7. import 'package:flutter_localizations/flutter_localizations.dart';
  8. import 'package:get/get.dart';
  9. import 'package:vitalapp/architecture/network_connectivity.dart';
  10. import 'global.dart';
  11. import 'routes/routes.dart';
  12. void main() async {
  13. runZonedGuarded(
  14. () async {
  15. try {
  16. WidgetsFlutterBinding.ensureInitialized();
  17. await Global.init();
  18. } catch (e) {
  19. logger.e('Global init Error', e);
  20. }
  21. runApp(const _App());
  22. },
  23. (error, stack) {
  24. logger.e('runZonedGuarded Error', error);
  25. // GlobalErrorHandler.handle(error, stack);
  26. },
  27. );
  28. }
  29. class _App extends StatefulWidget {
  30. const _App();
  31. @override
  32. State<StatefulWidget> createState() => _AppState();
  33. }
  34. class _AppState extends State<_App> with WidgetsBindingObserver {
  35. Timer? _netCheckTimer;
  36. @override
  37. void initState() {
  38. super.initState();
  39. WidgetsBinding.instance.addObserver(this);
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return GetMaterialApp(
  44. title: "杏聆荟健康平台",
  45. // locale: const Locale('zh'),
  46. localizationsDelegates: const [
  47. GlobalMaterialLocalizations.delegate,
  48. GlobalWidgetsLocalizations.delegate,
  49. GlobalCupertinoLocalizations.delegate,
  50. ],
  51. supportedLocales: const [
  52. Locale('en', 'US'), // English
  53. Locale('zh', 'CN'), // Chinese Simplified
  54. // other locales your app supports
  55. ],
  56. theme: ThemeData(
  57. // primaryColor: const Color.fromRGBO(0, 178, 237, 1),
  58. // TODO:
  59. primaryColor: Colors.blue,
  60. colorScheme:
  61. ColorScheme.fromSeed(seedColor: Color(Colors.blue.value - 40)),
  62. // colorScheme: ColorScheme.fromSeed(
  63. // // seedColor: const Color.fromRGBO(44, 119, 229, 1),
  64. // // seedColor: Colors.lightBlue,
  65. // seedColor: const Color.fromRGBO(0, 178, 237, 1),
  66. // ),
  67. // colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
  68. useMaterial3: true,
  69. fontFamily: "RubikMonoOne",
  70. fontFamilyFallback: const ["RubikMonoOne"],
  71. ),
  72. debugShowCheckedModeBanner: false,
  73. getPages: Routes.routes,
  74. initialRoute: "splash",
  75. // initialRoute: "/patient/create",
  76. // initialRoute: "/contract/signature",
  77. // initialRoute: "/",
  78. builder: EasyLoading.init(
  79. builder: (context, widget) {
  80. double designWidth = 1280.0; // 设计尺寸宽度:1280
  81. if (kIsWeb) designWidth = 1460.0;
  82. final size = MediaQuery.of(context).size;
  83. final scale = size.width / designWidth; // 计算缩放比例
  84. return FittedBox(
  85. fit: BoxFit.fitWidth,
  86. child: SizedBox(
  87. width: designWidth,
  88. height: size.height / scale,
  89. child: Center(child: widget ?? const SizedBox()),
  90. ),
  91. );
  92. },
  93. ),
  94. );
  95. }
  96. @override
  97. void dispose() {
  98. WidgetsBinding.instance.removeObserver(this);
  99. super.dispose();
  100. }
  101. @override
  102. void didChangeAppLifecycleState(AppLifecycleState state) {
  103. super.didChangeAppLifecycleState(state);
  104. switch (state) {
  105. case AppLifecycleState.resumed:
  106. _netCheckTimer?.cancel();
  107. _netCheckTimer = null;
  108. // 延迟300ms,等待其他APP状态恢复
  109. _netCheckTimer = Timer(const Duration(milliseconds: 300), () async {
  110. // 唤起后主动检查网络连接,防止状态不同步
  111. await netChecker.check();
  112. });
  113. break;
  114. case AppLifecycleState.inactive:
  115. break;
  116. case AppLifecycleState.paused:
  117. break;
  118. case AppLifecycleState.detached:
  119. break;
  120. }
  121. }
  122. }