main.dart 7.9 KB

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