mobile_skt/lib/global.dart

113 lines
3.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
2024-03-25 14:16:00 +08:00
import 'package:sk_base_mobile/store/dict.store.dart';
2024-04-10 17:08:26 +08:00
import 'package:sk_base_mobile/store/resource.store.dart';
2024-03-19 10:02:20 +08:00
import 'package:sk_base_mobile/util/loading_util.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 'package:timeago/timeago.dart';
import 'store/store.dart';
2024-03-19 08:59:08 +08:00
import 'package:flutter_native_splash/flutter_native_splash.dart';
/// 全局注册
class Global {
static Future init() async {
WidgetsFlutterBinding.ensureInitialized();
2024-03-29 16:21:32 +08:00
initialization(null);
/// 设置初始化竖屏
2024-03-18 15:54:06 +08:00
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
/// 设置跟随系统屏幕旋转
await SystemChrome.setPreferredOrientations(DeviceOrientation.values);
/// 设置系统UI 因用户反馈可能存在bug先隐藏功能
setSystemUi();
/// 初始化 几天前 的时区国际化
timeago.setLocaleMessages('zh_cn', MyCustomMessages());
2024-03-19 10:02:20 +08:00
/// 依赖注入Loading工具
await Get.putAsync<LoadingUtil>(() => LoadingUtil().init());
/// 依赖注入持久化
await Get.putAsync<StorageService>(() => StorageService().init());
/// 依赖注入Http
await Get.putAsync<DioService>(() => DioService().init());
/// 依赖注入app信息
await Get.putAsync<AppInfoService>(() => AppInfoService().init());
/// 依赖注入用户信息
await Get.putAsync<AuthStore>(() => AuthStore().init());
2024-03-25 14:16:00 +08:00
/// 依赖注入字典信息
await Get.putAsync<DictService>(() => DictService().init());
2024-04-10 17:08:26 +08:00
/// 依赖注入资源信息
await Get.putAsync<ResourceService>(() => ResourceService().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);
}
2024-03-29 16:21:32 +08:00
//启动图延时移除方法
static initialization(BuildContext? context) async {
//延迟3秒
await Future.delayed(const Duration(seconds: 3));
FlutterNativeSplash.remove();
}
}
// my_custom_messages.dart
class MyCustomMessages implements LookupMessages {
@override
String prefixAgo() => '';
@override
String prefixFromNow() => '';
@override
String suffixAgo() => '';
@override
String suffixFromNow() => '';
@override
String lessThanOneMinute(int seconds) => '现在';
@override
String aboutAMinute(int minutes) => '$minutes分钟';
@override
String minutes(int minutes) => '$minutes分钟';
@override
String aboutAnHour(int minutes) => '$minutes分钟';
@override
String hours(int hours) => '$hours小时';
@override
String aDay(int hours) => '$hours小时';
@override
String days(int days) => '$days天';
@override
String aboutAMonth(int days) => '$days天';
@override
String months(int months) => '$months月';
@override
String aboutAYear(int year) => '$year年';
@override
String years(int years) => '$years年';
@override
String wordSeparator() => ' ';
}