feat(locale): 实现 App 启动时语言和时区自动设置

- 新增系统语言/时区读取工具函数
- SessionStore 扩展支持时区存储
- 启动流程自动检测并保存系统语言/时区
- 注册时传递语言/时区到后端
- 登录后从服务器同步语言/时区
This commit is contained in:
ZL-Q
2026-04-28 17:18:16 +08:00
parent 14752cdcfa
commit a83001de0d
11 changed files with 402 additions and 14 deletions
+9
View File
@@ -14,6 +14,7 @@ class SessionStore {
static const String _emailKey = 'saved_email';
static const String _welcomeReadKey = 'has_seen_welcome_dialog';
static const String _localeKey = 'selected_locale';
static const String _timezoneKey = 'selected_timezone';
Future<void> saveToken(String token) async {
await _secureStorage.write(key: _tokenKey, value: token);
@@ -66,4 +67,12 @@ class SessionStore {
Future<String?> getLocaleTag() async {
return _kvStore.getString(_localeKey);
}
Future<void> saveTimezone(String timezone) async {
await _kvStore.setString(_timezoneKey, timezone);
}
Future<String?> getTimezone() async {
return _kvStore.getString(_timezoneKey);
}
}
@@ -0,0 +1,27 @@
import 'dart:ui';
Locale? resolveSystemLocale(Locale systemLocale) {
final lang = systemLocale.languageCode.toLowerCase();
final script = systemLocale.scriptCode;
final country = systemLocale.countryCode;
if (lang == 'en') {
return const Locale('en');
}
if (lang == 'zh') {
if (script == 'Hant' ||
country == 'TW' ||
country == 'HK' ||
country == 'MO') {
return const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant');
}
return const Locale('zh');
}
return null;
}
Locale getSystemLocale() {
return PlatformDispatcher.instance.locale;
}
@@ -0,0 +1,5 @@
import 'package:flutter_timezone/flutter_timezone.dart';
Future<String> getSystemTimezone() async {
return FlutterTimezone.getLocalTimezone();
}