main.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_report/router/report_service_impl.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_bugly/flutter_bugly.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() {
  31. //运行App
  32. FlutterBugly.postCatchedException(() async {
  33. //交给初始化构造器去统一初始化
  34. 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. backgroundColor: Colors.transparent,
  75. );
  76. /// SmartDialog 配置
  77. SmartDialog.config
  78. ..custom = SmartConfigCustom(
  79. maskColor: Colors.black.withOpacity(0.35),
  80. useAnimation: true,
  81. )
  82. ..attach = SmartConfigAttach(
  83. animationType: SmartAnimationType.scale,
  84. usePenetrate: false,
  85. )
  86. ..loading = SmartConfigLoading(
  87. backDismiss: true,
  88. clickMaskDismiss: true,
  89. )
  90. ..toast = SmartConfigToast(
  91. intervalTime: const Duration(milliseconds: 100),
  92. displayTime: const Duration(milliseconds: 2000),
  93. );
  94. }
  95. @override
  96. Widget build(BuildContext context) {
  97. //设置全局的状态栏文本样式
  98. SystemChrome.setSystemUIOverlayStyle(ThemeConfig.systemUiOverlayStyleLightThemeWhite);
  99. //路由管理,状态管理,依赖管理一切都始于GetMaterialApp
  100. return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) {
  101. return KeyboardDismissOnTap(
  102. dismissOnCapturedTaps: false,
  103. child: GetMaterialApp(
  104. //顶部是否展示Debug图标
  105. debugShowCheckedModeBanner: true,
  106. //是否展示Log
  107. enableLog: true,
  108. //默认路由与路由表的加载
  109. initialRoute: RouterPath.SPLASH,
  110. getPages: PageRouter.routes + BasicPageRouter.routes + AuthPageRouter.routes + JobPageRouter.routes,
  111. //对原生导航的兼容;SmartDialog路由配置生命周期处理
  112. navigatorObservers: [GetXRouterObserver(), FlutterSmartDialog.observer, routeObserver],
  113. //默认页面动画
  114. defaultTransition: Transition.rightToLeft,
  115. smartManagement: SmartManagement.keepFactory,
  116. //网页Title显示
  117. title: 'YYBusiness-ER',
  118. //样式相关
  119. theme: ThemeConfig.lightTheme,
  120. darkTheme: ThemeConfig.darkTheme,
  121. themeMode: ThemeMode.light,
  122. //本地化相关
  123. locale: TranslationService.locale,
  124. fallbackLocale: TranslationService.fallbackLocale,
  125. localizationsDelegates: const [
  126. GlobalMaterialLocalizations.delegate,
  127. GlobalWidgetsLocalizations.delegate,
  128. GlobalCupertinoLocalizations.delegate,
  129. ],
  130. supportedLocales: const [
  131. Locale('zh', 'CH'),
  132. Locale('en', 'US'),
  133. ],
  134. translations: TranslationService(),
  135. //SmartDialog初始化默认Loading与Toast
  136. builder: FlutterSmartDialog.init(
  137. toastBuilder: (String msg) {
  138. return CustomToastWidget(msg: msg);
  139. },
  140. loadingBuilder: (String msg) {
  141. return CustomLoadingWidget(msg: msg == 'loading...' ? 'Loading...'.tr : msg);
  142. },
  143. notifyStyle: FlutterSmartNotifyStyle(
  144. successBuilder: (String msg) => CustomSuccessWidget(msg: msg),
  145. failureBuilder: (String msg) => CustomFailureWidget(msg: msg),
  146. errorBuilder: (String msg) => CustomErrorWidget(msg: msg),
  147. alertBuilder: (String msg) => CustomErrorWidget(msg: msg),
  148. warningBuilder: (String msg) => CustomErrorWidget(msg: msg),
  149. ),
  150. ),
  151. ),
  152. );
  153. });
  154. }
  155. }