main.dart 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import 'dart:io';
  2. import 'package:flustars/flustars.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  6. import 'package:ftrecruiter/services_injection.dart';
  7. import 'package:get/get.dart';
  8. import 'package:ftrecruiter/app_binding.dart';
  9. import 'package:ftrecruiter/comm/utils/device_utils.dart';
  10. import 'package:ftrecruiter/comm/utils/handle_error_utils.dart';
  11. import 'package:ftrecruiter/comm/utils/log_utils.dart';
  12. import 'package:ftrecruiter/comm/widget/dialog/custom_loading_widget.dart';
  13. import 'package:ftrecruiter/comm/widget/dialog/custom_toast_widget.dart';
  14. import 'package:ftrecruiter/local/language/translation_service.dart';
  15. import 'package:ftrecruiter/local/theme/theme_config.dart';
  16. import 'package:ftrecruiter/router/getx_router_observer.dart';
  17. import 'package:ftrecruiter/router/page_router.dart';
  18. void main() async {
  19. //框架初始化
  20. WidgetsFlutterBinding.ensureInitialized();
  21. //注入Service
  22. // await ServicesInjection.init();
  23. // SP初始化
  24. await SpUtil.getInstance();
  25. // 设备信息初始化 - 判断运行在哪一个平台
  26. await Device.initDeviceInfo();
  27. //运行App
  28. handleError(() => runApp(MyApp()));
  29. //处理状态栏
  30. SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]);
  31. //沉浸式
  32. if (Platform.isAndroid) {
  33. SystemUiOverlayStyle style = const SystemUiOverlayStyle(
  34. statusBarColor: Colors.transparent,
  35. //设置为黑色字体
  36. statusBarIconBrightness: Brightness.dark);
  37. SystemChrome.setSystemUIOverlayStyle(style);
  38. }
  39. }
  40. class MyApp extends StatelessWidget {
  41. MyApp({Key? key}) : super(key: key) {
  42. //Log框架初始化
  43. Log.init();
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. //路由管理,状态管理,依赖管理一切都始于GetMaterialApp
  48. return GetMaterialApp(
  49. //顶部是否展示Debug图标
  50. debugShowCheckedModeBanner: true,
  51. //是否展示Log
  52. enableLog: true,
  53. //默认路由与路由表的加载
  54. initialRoute: RouterPath.SPLASH,
  55. getPages: PageRouter.routes,
  56. //对原生导航的兼容
  57. navigatorObservers: [GetXRouterObserver()],
  58. //默认页面动画
  59. defaultTransition: Transition.rightToLeft,
  60. //异步依赖注入ApiService ApiRepository等对象
  61. initialBinding: AppBinding(),
  62. smartManagement: SmartManagement.keepFactory,
  63. //网页Title显示
  64. title: 'FullTime Recruiter',
  65. //样式相关
  66. theme: ThemeConfig.lightTheme,
  67. darkTheme: ThemeConfig.darkTheme,
  68. themeMode: ThemeMode.system,
  69. //本地化相关
  70. locale: TranslationService.locale,
  71. fallbackLocale: TranslationService.fallbackLocale,
  72. translations: TranslationService(),
  73. //SmartDialog初始化默认Loading与Toast
  74. builder: FlutterSmartDialog.init(
  75. toastBuilder: (String msg) {
  76. return CustomToastWidget(msg: msg);
  77. },
  78. loadingBuilder: (String msg) {
  79. return CustomLoadingWidget(msg: 'loading'.tr);
  80. },
  81. ),
  82. );
  83. }
  84. }