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