feat(app): 剧场页九宫格与极简我的页

This commit is contained in:
Zhou Weidong committed 2026-10-20 05:28:51 +08:00
1 parent dc8ca7b743
commit 35338cbfc8
46 files changed
+2353 -4358

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
// Author: fruit.com.cn
import 'package:flutter/widgets.dart';
/// 将系统语言解析为受支持的语言;不支持时回退印尼语。
Locale resolveAppLocale(Locale? deviceLocale) {
return switch (deviceLocale?.languageCode) {
'zh' => const Locale('zh'),
'en' => const Locale('en'),
_ => const Locale('id'),
};
}
-56
View File
@@ -1,56 +0,0 @@
// Author: fruit.com.cn
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Resolves the selected or system language to one of the supported app locales.
///
/// Indonesian is the launch-market fallback when a device uses an unsupported
/// language. The legacy `in` code is treated as Indonesian as well.
Locale resolveAppLocale(Locale? selected, Locale? deviceLocale) {
final code = (selected ?? deviceLocale)?.languageCode;
return switch (code) {
'zh' => const Locale('zh'),
'en' => const Locale('en'),
_ => const Locale('id'),
};
}
class LocaleController extends ChangeNotifier {
LocaleController({SharedPreferencesAsync? preferences})
: _preferences = preferences ?? SharedPreferencesAsync();
final SharedPreferencesAsync _preferences;
Locale? _locale;
Locale? get locale => _locale;
Future<void> load() async {
try {
final code = await _preferences.getString('ui.locale');
_locale = switch (code) {
'en' => const Locale('en'),
'zh' => const Locale('zh'),
'id' => const Locale('id'),
_ => null,
};
notifyListeners();
} catch (_) {
// The system locale remains usable if preferences are unavailable.
}
}
Future<void> select(String code) async {
_locale = switch (code) {
'en' => const Locale('en'),
'zh' => const Locale('zh'),
'id' => const Locale('id'),
_ => null,
};
notifyListeners();
try {
await _preferences.setString('ui.locale', code);
} catch (_) {
// Preference persistence is best effort for this prototype.
}
}
}