feat: 新增语言设置(跟随系统/简体中文/English),导航双语
This commit is contained in:
1 parent
ef88390b34
commit
2eb3f42731
5 files changed
+109
-10
No files matched your search
@@ -13,6 +13,7 @@ import '../../providers/theme_provider.dart';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
import 'help_page.dart';
|
||||
import 'download_settings_page.dart';
|
||||
import '../../providers/language_provider.dart';
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
const SettingsPage({super.key});
|
||||
@@ -133,6 +134,32 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
if (await _applyWallpaper(path, 'image')) _refreshUI();
|
||||
}
|
||||
|
||||
String _languageName(LanguageMode m) => switch (m) {
|
||||
LanguageMode.system => '跟随系统 / System',
|
||||
LanguageMode.zh => '简体中文',
|
||||
LanguageMode.en => 'English',
|
||||
};
|
||||
|
||||
Future<void> _pickLanguage() async {
|
||||
final provider = context.read<LanguageProvider>();
|
||||
final mode = await showDialog<LanguageMode>(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
title: const Text('语言 / Language'),
|
||||
children: [
|
||||
for (final m in LanguageMode.values)
|
||||
RadioListTile<LanguageMode>(
|
||||
title: Text(_languageName(m)),
|
||||
value: m,
|
||||
groupValue: provider.mode,
|
||||
onChanged: (v) => Navigator.pop(context, v),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (mode != null) await provider.setMode(mode);
|
||||
}
|
||||
|
||||
Future<void> _pickVideo() async {
|
||||
final result = await FilePicker.platform.pickFiles(type: FileType.video);
|
||||
if (result == null) return;
|
||||
@@ -280,6 +307,16 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
],
|
||||
const Divider(),
|
||||
|
||||
// ---------- 语言 ----------
|
||||
ListTile(
|
||||
leading: const Icon(Icons.language),
|
||||
title: const Text('语言 / Language'),
|
||||
subtitle: Text(_languageName(context.watch<LanguageProvider>().mode)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _pickLanguage(),
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// ---------- 下载与镜像 ----------
|
||||
ListTile(
|
||||
leading: const Icon(Icons.download_outlined),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
import '../../core/utils/rcon_client.dart';
|
||||
import '../../providers/rcon_provider.dart';
|
||||
import '../../providers/language_provider.dart';
|
||||
import '../console/console_page.dart';
|
||||
import '../dashboard/dashboard_page.dart';
|
||||
import '../dashboard/server_picker_bar.dart';
|
||||
@@ -24,6 +25,10 @@ class _MainShellState extends State<MainShell> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final en = context.watch<LanguageProvider>().isEnglish;
|
||||
final labels = en
|
||||
? ['Servers', 'Console', 'Players', 'Mods', 'Terminal', 'Me']
|
||||
: ['服务器', '控制台', '玩家', '模组', '终端', '我的'];
|
||||
final pages = [
|
||||
const DashboardPage(),
|
||||
const _ConsoleTab(),
|
||||
@@ -37,17 +42,29 @@ class _MainShellState extends State<MainShell> {
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: _index,
|
||||
onDestinationSelected: (i) => setState(() => _index = i),
|
||||
destinations: const [
|
||||
NavigationDestination(icon: Icon(Icons.dns_outlined), selectedIcon: Icon(Icons.dns), label: '服务器'),
|
||||
NavigationDestination(icon: Icon(Icons.terminal_outlined), selectedIcon: Icon(Icons.terminal), label: '控制台'),
|
||||
NavigationDestination(icon: Icon(Icons.group_outlined), selectedIcon: Icon(Icons.group), label: '玩家'),
|
||||
NavigationDestination(icon: Icon(Icons.extension_outlined), selectedIcon: Icon(Icons.extension), label: '模组'),
|
||||
NavigationDestination(icon: Icon(Icons.terminal), selectedIcon: Icon(Icons.terminal), label: '终端'),
|
||||
NavigationDestination(icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: '我的'),
|
||||
destinations: [
|
||||
for (var i = 0; i < 6; i++)
|
||||
NavigationDestination(
|
||||
icon: _navIcon(i, false),
|
||||
selectedIcon: _navIcon(i, true),
|
||||
label: labels[i],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _navIcon(int i, bool selected) {
|
||||
final list = [
|
||||
[Icons.dns_outlined, Icons.dns],
|
||||
[Icons.terminal_outlined, Icons.terminal],
|
||||
[Icons.group_outlined, Icons.group],
|
||||
[Icons.extension_outlined, Icons.extension],
|
||||
[Icons.terminal, Icons.terminal],
|
||||
[Icons.settings_outlined, Icons.settings],
|
||||
];
|
||||
return Icon(list[i][selected ? 1 : 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/// 页签通用骨架:带标题 AppBar(无服务器选中时副标题为空)。
|
||||
|
||||
Reference in new issue
Block a user