main.dart 7.4 KB

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