main.dart 7.6 KB

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