main.dart 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import 'package:cpt_auth/router/auth_service_impl.dart';
  2. import 'package:cpt_auth/router/page_router.dart';
  3. import 'package:cpt_job/router/job_service_impl.dart';
  4. import 'package:cpt_job/router/page_router.dart';
  5. import 'package:cpt_labour/router/labour_service_impl.dart';
  6. import 'package:cpt_labour/router/page_router.dart';
  7. import 'package:cpt_report/router/report_service_impl.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter/services.dart';
  10. import 'package:flutter_bugly/flutter_bugly.dart';
  11. import 'package:flutter_localizations/flutter_localizations.dart';
  12. import 'package:initializer/global_services_injection.dart';
  13. import 'package:initializer/app_initializer.dart';
  14. import 'package:plugin_basic/basic_export.dart';
  15. import 'package:router/componentRouter/auth_service.dart';
  16. import 'package:router/componentRouter/job_service.dart';
  17. import 'package:router/componentRouter/labour_service.dart';
  18. import 'package:router/componentRouter/report_service.dart';
  19. import 'package:cs_resources/local/theme/theme_config.dart';
  20. import 'package:cs_resources/local/language/translation_service.dart';
  21. import 'package:router/path/router_path.dart';
  22. import 'package:router/observer/getx_router_observer.dart';
  23. import 'package:plugin_basic/router/basic_page_router.dart';
  24. import 'package:widgets/dialog/custom_toast_widget.dart';
  25. import 'package:widgets/dialog/custom_error_widget.dart';
  26. import 'package:widgets/dialog/custom_failure_widget.dart';
  27. import 'package:widgets/dialog/custom_success_widget.dart';
  28. import 'package:widgets/dialog/custom_loading_widget.dart';
  29. import 'package:widgets/widget_export.dart';
  30. import 'router/page_router.dart';
  31. void main() {
  32. //运行App
  33. FlutterBugly.postCatchedException(() async {
  34. //交给初始化构造器去统一初始化
  35. AppInitializer.initializeRunalone();
  36. //全局自定义单例服务的注入
  37. GlobalServicesInjection.init(additionalDependencies: () {
  38. Get.lazyPut<AuthService>(() => AuthServiceImpl());
  39. Get.lazyPut<LabourService>(() => LabourServiceImpl());
  40. Get.lazyPut<JobService>(() => JobServiceImpl());
  41. Get.lazyPut<ReportService>(() => ReportServiceImpl());
  42. });
  43. runApp(MyApp());
  44. });
  45. }
  46. class MyApp extends StatelessWidget {
  47. MyApp({Key? key}) : super(key: key) {
  48. /// 全局设置 EasyRefresh 的样式
  49. EasyRefresh.defaultHeaderBuilder = () => ClassicHeader(
  50. dragText: 'Pull to refresh'.tr,
  51. armedText: 'Release ready'.tr,
  52. readyText: 'Refreshing...'.tr,
  53. processingText: 'Refreshing...'.tr,
  54. processedText: 'Succeeded'.tr,
  55. noMoreText: 'No more'.tr,
  56. failedText: 'Failed'.tr,
  57. messageText: 'Last updated at %T'.tr,
  58. textStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 14),
  59. messageStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 12),
  60. iconTheme: const IconThemeData(color: Color(0XFFAECAE5)),
  61. backgroundColor: Colors.transparent,
  62. );
  63. EasyRefresh.defaultFooterBuilder = () => ClassicFooter(
  64. dragText: 'Pull to load'.tr,
  65. armedText: 'Release ready'.tr,
  66. readyText: 'Loading...'.tr,
  67. processingText: 'Loading...'.tr,
  68. processedText: 'Succeeded'.tr,
  69. noMoreText: 'No more'.tr,
  70. failedText: 'Failed'.tr,
  71. showMessage: false,
  72. triggerOffset: 50,
  73. iconDimension: 22,
  74. textStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 14),
  75. messageStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 12),
  76. iconTheme: const IconThemeData(color: Color(0XFFAECAE5)),
  77. backgroundColor: Colors.transparent,
  78. );
  79. /// SmartDialog 配置
  80. SmartDialog.config
  81. ..custom = SmartConfigCustom(
  82. maskColor: Colors.black.withOpacity(0.35),
  83. useAnimation: true,
  84. )
  85. ..attach = SmartConfigAttach(
  86. animationType: SmartAnimationType.scale,
  87. usePenetrate: false,
  88. )
  89. ..loading = SmartConfigLoading(
  90. backDismiss: true,
  91. clickMaskDismiss: true,
  92. )
  93. ..toast = SmartConfigToast(
  94. intervalTime: const Duration(milliseconds: 100),
  95. displayTime: const Duration(milliseconds: 2000),
  96. );
  97. }
  98. @override
  99. Widget build(BuildContext context) {
  100. //设置全局的状态栏文本样式
  101. SystemChrome.setSystemUIOverlayStyle(ThemeConfig.systemUiOverlayStyleLightThemeWhite);
  102. //路由管理,状态管理,依赖管理一切都始于GetMaterialApp
  103. return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) {
  104. return KeyboardDismissOnTap(
  105. dismissOnCapturedTaps: false,
  106. child: GetMaterialApp(
  107. //顶部是否展示Debug图标
  108. debugShowCheckedModeBanner: true,
  109. //是否展示Log
  110. enableLog: true,
  111. //默认路由与路由表的加载
  112. initialRoute: RouterPath.SPLASH,
  113. getPages: PageRouter.routes + BasicPageRouter.routes + AuthPageRouter.routes + JobPageRouter.routes + LabourPageRouter.routes,
  114. //对原生导航的兼容;SmartDialog路由配置生命周期处理
  115. navigatorObservers: [GetXRouterObserver(), FlutterSmartDialog.observer, routeObserver],
  116. //默认页面动画
  117. defaultTransition: Transition.rightToLeft,
  118. smartManagement: SmartManagement.keepFactory,
  119. //网页Title显示
  120. title: 'YYBusiness-ER',
  121. //样式相关
  122. theme: ThemeConfig.lightTheme,
  123. darkTheme: ThemeConfig.darkTheme,
  124. themeMode: ThemeMode.light,
  125. //本地化相关
  126. locale: TranslationService.locale,
  127. fallbackLocale: TranslationService.fallbackLocale,
  128. localizationsDelegates: const [
  129. GlobalMaterialLocalizations.delegate,
  130. GlobalWidgetsLocalizations.delegate,
  131. GlobalCupertinoLocalizations.delegate,
  132. ],
  133. supportedLocales: const [
  134. Locale('zh', 'CH'),
  135. Locale('en', 'US'),
  136. ],
  137. translations: TranslationService(),
  138. //SmartDialog初始化默认Loading与Toast
  139. builder: FlutterSmartDialog.init(
  140. toastBuilder: (String msg) {
  141. return CustomToastWidget(msg: msg);
  142. },
  143. loadingBuilder: (String msg) {
  144. return CustomLoadingWidget(msg: msg == 'loading...' ? 'Loading...'.tr : msg);
  145. },
  146. notifyStyle: FlutterSmartNotifyStyle(
  147. successBuilder: (String msg) => CustomSuccessWidget(msg: msg),
  148. failureBuilder: (String msg) => CustomFailureWidget(msg: msg),
  149. errorBuilder: (String msg) => CustomErrorWidget(msg: msg),
  150. alertBuilder: (String msg) => CustomErrorWidget(msg: msg),
  151. warningBuilder: (String msg) => CustomErrorWidget(msg: msg),
  152. ),
  153. ),
  154. ),
  155. );
  156. });
  157. }
  158. }