feat: 项目框架,全局空间处理

This commit is contained in:
chengsiwen committed 2026-06-26 15:58:29 +08:00
1 parent 4df6be7411
commit d90d023e85
36 files changed
+1166 -118

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import 'dart:ui';
import 'package:get/get.dart';
import '../../utils/tools/app_sp.dart';
import '../const/common_string.dart';
class AppLanguage extends Translations {
static List<Locale> supportedLocales = [
Locale('en', 'US'),
Locale('zh', 'CN'),
Get.deviceLocale!
];
///切换语言
static void changeLanguage(int languageIndex) {
Locale? appLocale;
switch (languageIndex) {
case 0: //English
appLocale = const Locale('en', 'US');
break;
case 1: //简体中文
appLocale = const Locale('zh', 'CN');
break;
case 2: //跟隨系統
appLocale = Get.deviceLocale;
break;
default:
appLocale = Get.deviceLocale;
break;
}
//保存到本地
// AppBox.shared.language = languageIndex;
// AppSp().setString(CommonString.language, appLocale!.languageCode);
// AppSp().setInt(CommonString.languageIndex, languageIndex);
Get.updateLocale(appLocale!);
}
static Future<Locale?> getLocale() async {
int lint = await AppSp().getInt(CommonString.languageIndex);
return supportedLocales[lint];
}
@override
Map<String, Map<String, String>> get keys => {
'en_US': {
},
'zh_CN': {
}
};
}
+19
View File
@@ -0,0 +1,19 @@
import 'package:get/get.dart';
class AppLocale {
static String get languageCode =>
(Get.locale?.languageCode ?? 'en').toLowerCase();
static bool get isZh => languageCode.startsWith('zh');
static String pick({
required String zh,
required String en,
}) {
final String first = isZh ? zh : en;
final String second = isZh ? en : zh;
if (first.trim().isNotEmpty) return first;
if (second.trim().isNotEmpty) return second;
return '';
}
}
+4
View File
@@ -0,0 +1,4 @@
class LocalString {
}