import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:timeago/timeago.dart' as timeago; import 'package:sk_base_mobile/constants/cache_key.dart'; import 'package:sk_base_mobile/services/app_info.service.dart'; import 'package:sk_base_mobile/services/dio.service.dart'; import 'package:sk_base_mobile/services/storage.service.dart'; import 'store/store.dart'; /// 全局注册 class Global { static Future init() async { WidgetsFlutterBinding.ensureInitialized(); /// 设置初始化竖屏 // await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); /// 设置跟随系统屏幕旋转 await SystemChrome.setPreferredOrientations(DeviceOrientation.values); /// 设置系统UI 因用户反馈可能存在bug先隐藏功能 setSystemUi(); /// 初始化 几天前 的时区国际化 timeago.setLocaleMessages('en', timeago.EnMessages()); /// 依赖注入持久化 await Get.putAsync(() => StorageService().init()); /// 依赖注入Http await Get.putAsync(() => DioService().init()); /// 依赖注入app信息 await Get.putAsync(() => AppInfoService().init()); /// 依赖注入用户信息 await Get.putAsync(() => AuthStore().init()); if (StorageService.to.getString(CacheKeys.token, isWithUser: false) != null) { /// 这里做一些缓存初始化后的操作 } } static void setSystemUi() { SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle( statusBarColor: Colors.transparent, statusBarBrightness: Brightness.light, statusBarIconBrightness: Brightness.light, ); SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle); } }