feat(mobile): in-app locale switching

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-19 05:00:11 +08:00
parent 955f9b13c1
commit 8f3966d7b5
8 changed files with 548 additions and 17 deletions
+48 -2
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../app/locale_controller.dart';
import '../core/api_client.dart';
import '../features/uploads/engine_scope.dart';
import '../l10n/app_localizations.dart';
@@ -56,10 +57,53 @@ class _HomePageState extends State<HomePage> {
}
}
/// 设置页(P3 Task 3:修改密码入口 + 退出登录;Task 10 补语言切换持久化)。
/// 设置页(P3 Task 3:修改密码入口 + 退出登录;Task 10:语言切换)。
class SettingsTab extends ConsumerWidget {
const SettingsTab({super.key});
/// 档位 → 展示名(语言名固定以自身语言书写,不随当前界面语言变化)。
static String _choiceLabel(AppLocalizations l10n, AppLocaleChoice choice) =>
switch (choice) {
AppLocaleChoice.system => l10n.localeFollowSystem,
AppLocaleChoice.zh => l10n.localeChinese,
AppLocaleChoice.en => l10n.localeEnglish,
};
Future<void> _pickLocale(
BuildContext context,
WidgetRef ref,
AppLocaleChoice current,
) {
return showModalBottomSheet<void>(
context: context,
showDragHandle: true,
builder: (sheetContext) {
final l10n = AppLocalizations.of(sheetContext);
// 打开时刻的快照即可:选中即 pop,无滞留期间的陈旧选中态。
return SafeArea(
child: RadioGroup<AppLocaleChoice>(
groupValue: current,
onChanged: (choice) {
if (choice == null) return;
ref.read(localeSettingsProvider.notifier).setChoice(choice);
Navigator.of(sheetContext).pop();
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final choice in AppLocaleChoice.values)
RadioListTile<AppLocaleChoice>(
value: choice,
title: Text(_choiceLabel(l10n, choice)),
),
],
),
),
);
},
);
}
Future<void> _logout(BuildContext context, WidgetRef ref) async {
// api.logout 尽力而为(服务端撤销失败也照常本地清会话——客户端内已处理)。
await ref.read(apiClientProvider).logout();
@@ -72,6 +116,7 @@ class SettingsTab extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
final choice = ref.watch(localeSettingsProvider);
return Scaffold(
appBar: AppBar(title: Text(l10n.settings)),
body: ListView(
@@ -79,7 +124,8 @@ class SettingsTab extends ConsumerWidget {
ListTile(
leading: const Icon(Icons.language),
title: Text(l10n.language),
subtitle: Text(l10n.localeFollowSystem),
subtitle: Text(_choiceLabel(l10n, choice)),
onTap: () => _pickLocale(context, ref, choice),
),
ListTile(
leading: const Icon(Icons.password_outlined),