import 'package:cpt_auth/router/auth_service_impl.dart'; import 'package:cpt_auth/router/page_router.dart'; import 'package:cpt_job/router/job_service_impl.dart'; import 'package:cpt_job/router/page_router.dart'; import 'package:cpt_labour/router/labour_service_impl.dart'; import 'package:cpt_labour/router/page_router.dart'; import 'package:cpt_report/router/report_service_impl.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bugly/flutter_bugly.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:initializer/global_services_injection.dart'; import 'package:initializer/app_initializer.dart'; import 'package:plugin_basic/basic_export.dart'; import 'package:router/componentRouter/auth_service.dart'; import 'package:router/componentRouter/job_service.dart'; import 'package:router/componentRouter/labour_service.dart'; import 'package:router/componentRouter/report_service.dart'; import 'package:cs_resources/local/theme/theme_config.dart'; import 'package:cs_resources/local/language/translation_service.dart'; import 'package:router/path/router_path.dart'; import 'package:router/observer/getx_router_observer.dart'; import 'package:plugin_basic/router/basic_page_router.dart'; import 'package:widgets/dialog/custom_toast_widget.dart'; import 'package:widgets/dialog/custom_error_widget.dart'; import 'package:widgets/dialog/custom_failure_widget.dart'; import 'package:widgets/dialog/custom_success_widget.dart'; import 'package:widgets/dialog/custom_loading_widget.dart'; import 'package:widgets/widget_export.dart'; import 'router/page_router.dart'; void main() { //运行App FlutterBugly.postCatchedException(() async { //交给初始化构造器去统一初始化 AppInitializer.initializeRunalone(); //全局自定义单例服务的注入 GlobalServicesInjection.init(additionalDependencies: () { Get.lazyPut(() => AuthServiceImpl()); Get.lazyPut(() => LabourServiceImpl()); Get.lazyPut(() => JobServiceImpl()); Get.lazyPut(() => ReportServiceImpl()); }); runApp(MyApp()); }); } class MyApp extends StatelessWidget { MyApp({Key? key}) : super(key: key) { /// 全局设置 EasyRefresh 的样式 EasyRefresh.defaultHeaderBuilder = () => ClassicHeader( dragText: 'Pull to refresh'.tr, armedText: 'Release ready'.tr, readyText: 'Refreshing...'.tr, processingText: 'Refreshing...'.tr, processedText: 'Succeeded'.tr, noMoreText: 'No more'.tr, failedText: 'Failed'.tr, messageText: 'Last updated at %T'.tr, textStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 14), messageStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 12), iconTheme: const IconThemeData(color: Color(0XFFAECAE5)), backgroundColor: Colors.transparent, ); EasyRefresh.defaultFooterBuilder = () => ClassicFooter( dragText: 'Pull to load'.tr, armedText: 'Release ready'.tr, readyText: 'Loading...'.tr, processingText: 'Loading...'.tr, processedText: 'Succeeded'.tr, noMoreText: 'No more'.tr, failedText: 'Failed'.tr, showMessage: false, triggerOffset: 50, iconDimension: 22, textStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 14), messageStyle: const TextStyle(color: Color(0XFFAECAE5), fontSize: 12), iconTheme: const IconThemeData(color: Color(0XFFAECAE5)), backgroundColor: Colors.transparent, ); /// SmartDialog 配置 SmartDialog.config ..custom = SmartConfigCustom( maskColor: Colors.black.withOpacity(0.35), useAnimation: true, ) ..attach = SmartConfigAttach( animationType: SmartAnimationType.scale, usePenetrate: false, ) ..loading = SmartConfigLoading( backDismiss: true, clickMaskDismiss: true, ) ..toast = SmartConfigToast( intervalTime: const Duration(milliseconds: 100), displayTime: const Duration(milliseconds: 2000), ); } @override Widget build(BuildContext context) { //设置全局的状态栏文本样式 SystemChrome.setSystemUIOverlayStyle(ThemeConfig.systemUiOverlayStyleLightThemeWhite); //路由管理,状态管理,依赖管理一切都始于GetMaterialApp return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) { return KeyboardDismissOnTap( dismissOnCapturedTaps: false, child: GetMaterialApp( //顶部是否展示Debug图标 debugShowCheckedModeBanner: true, //是否展示Log enableLog: true, //默认路由与路由表的加载 initialRoute: RouterPath.SPLASH, getPages: PageRouter.routes + BasicPageRouter.routes + AuthPageRouter.routes + JobPageRouter.routes + LabourPageRouter.routes, //对原生导航的兼容;SmartDialog路由配置生命周期处理 navigatorObservers: [GetXRouterObserver(), FlutterSmartDialog.observer, routeObserver], //默认页面动画 defaultTransition: Transition.rightToLeft, smartManagement: SmartManagement.keepFactory, //网页Title显示 title: 'YYBusiness-ER', //样式相关 theme: ThemeConfig.lightTheme, darkTheme: ThemeConfig.darkTheme, themeMode: ThemeMode.light, //本地化相关 locale: TranslationService.locale, fallbackLocale: TranslationService.fallbackLocale, localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('zh', 'CH'), Locale('en', 'US'), ], translations: TranslationService(), //SmartDialog初始化默认Loading与Toast builder: FlutterSmartDialog.init( toastBuilder: (String msg) { return CustomToastWidget(msg: msg); }, loadingBuilder: (String msg) { return CustomLoadingWidget(msg: msg == 'loading...' ? 'Loading...'.tr : msg); }, notifyStyle: FlutterSmartNotifyStyle( successBuilder: (String msg) => CustomSuccessWidget(msg: msg), failureBuilder: (String msg) => CustomFailureWidget(msg: msg), errorBuilder: (String msg) => CustomErrorWidget(msg: msg), alertBuilder: (String msg) => CustomErrorWidget(msg: msg), warningBuilder: (String msg) => CustomErrorWidget(msg: msg), ), ), ), ); }); } }