2026-09-19 00:22:04 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2026-09-19 01:19:57 +08:00
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2026-09-19 00:22:04 +08:00
|
|
|
|
|
2026-09-19 05:00:11 +08:00
|
|
|
|
import '../app/locale_controller.dart';
|
2026-09-19 01:19:57 +08:00
|
|
|
|
import '../core/api_client.dart';
|
2026-09-19 04:47:31 +08:00
|
|
|
|
import '../features/uploads/engine_scope.dart';
|
2026-09-21 14:55:29 +08:00
|
|
|
|
import '../features/uploads/queue_controller.dart';
|
2026-09-19 00:22:04 +08:00
|
|
|
|
import '../l10n/app_localizations.dart';
|
2026-09-21 17:20:43 +08:00
|
|
|
|
import '../ui/components/section_header.dart';
|
|
|
|
|
|
import '../ui/tokens.dart';
|
2026-09-19 01:56:38 +08:00
|
|
|
|
import 'albums_tab.dart';
|
2026-09-19 04:47:31 +08:00
|
|
|
|
import 'queue_tab.dart';
|
2026-09-19 00:22:04 +08:00
|
|
|
|
|
2026-09-21 17:20:43 +08:00
|
|
|
|
/// 应用展示版本(About 分组):与 pubspec version 对齐的缺省值,
|
|
|
|
|
|
/// `--dart-define=APP_VERSION=...` 覆盖(未引入 package_info,零新依赖)。
|
|
|
|
|
|
const String kAppVersion = String.fromEnvironment(
|
|
|
|
|
|
'APP_VERSION',
|
|
|
|
|
|
defaultValue: '1.0.0',
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-09-21 14:55:29 +08:00
|
|
|
|
/// 主壳:底部导航「相册 / 上传 / 设置」(UI-01 §4.1)。
|
|
|
|
|
|
///
|
|
|
|
|
|
/// IndexedStack 保持三页签状态;「上传」页签角标 = 当前账号未结束任务数
|
|
|
|
|
|
/// ([unfinishedCountOf],TaskStore 账号硬隔离,不跨账号),为 0 时隐藏。
|
|
|
|
|
|
class HomePage extends ConsumerStatefulWidget {
|
2026-09-19 00:22:04 +08:00
|
|
|
|
const HomePage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2026-09-21 14:55:29 +08:00
|
|
|
|
ConsumerState<HomePage> createState() => _HomePageState();
|
2026-09-19 00:22:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-21 14:55:29 +08:00
|
|
|
|
class _HomePageState extends ConsumerState<HomePage> {
|
2026-09-19 00:22:04 +08:00
|
|
|
|
int _selectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final l10n = AppLocalizations.of(context);
|
2026-09-21 14:55:29 +08:00
|
|
|
|
final badgeCount = ref.watch(uploadBadgeCountProvider);
|
2026-09-19 00:22:04 +08:00
|
|
|
|
return Scaffold(
|
|
|
|
|
|
body: IndexedStack(
|
|
|
|
|
|
index: _selectedIndex,
|
2026-09-21 14:55:29 +08:00
|
|
|
|
children: const [AlbumsTab(), QueueTab(), SettingsTab()],
|
2026-09-19 00:22:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
bottomNavigationBar: NavigationBar(
|
|
|
|
|
|
selectedIndex: _selectedIndex,
|
|
|
|
|
|
onDestinationSelected: (index) =>
|
|
|
|
|
|
setState(() => _selectedIndex = index),
|
|
|
|
|
|
destinations: [
|
|
|
|
|
|
NavigationDestination(
|
|
|
|
|
|
icon: const Icon(Icons.photo_library_outlined),
|
|
|
|
|
|
selectedIcon: const Icon(Icons.photo_library),
|
2026-09-21 14:55:29 +08:00
|
|
|
|
label: l10n.navAlbums,
|
2026-09-19 00:22:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
NavigationDestination(
|
2026-09-21 14:55:29 +08:00
|
|
|
|
icon: _UploadTabIcon(
|
|
|
|
|
|
count: badgeCount,
|
|
|
|
|
|
icon: Icons.cloud_upload_outlined,
|
|
|
|
|
|
),
|
|
|
|
|
|
selectedIcon: _UploadTabIcon(
|
|
|
|
|
|
count: badgeCount,
|
|
|
|
|
|
icon: Icons.cloud_upload,
|
|
|
|
|
|
),
|
|
|
|
|
|
label: l10n.navUploads,
|
2026-09-19 00:22:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
NavigationDestination(
|
|
|
|
|
|
icon: const Icon(Icons.settings_outlined),
|
|
|
|
|
|
selectedIcon: const Icon(Icons.settings),
|
2026-09-21 14:55:29 +08:00
|
|
|
|
label: l10n.navSettings,
|
2026-09-19 00:22:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-21 14:55:29 +08:00
|
|
|
|
/// 上传页签图标 + 未完成任务角标(≤0 时隐藏 Badge,仅图标)。
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Semantics 携带本地化计数文案(读屏不依赖角标视觉)。
|
|
|
|
|
|
class _UploadTabIcon extends StatelessWidget {
|
|
|
|
|
|
const _UploadTabIcon({required this.count, required this.icon});
|
|
|
|
|
|
|
|
|
|
|
|
final int count;
|
|
|
|
|
|
final IconData icon;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
if (count <= 0) return Icon(icon);
|
|
|
|
|
|
return Semantics(
|
|
|
|
|
|
label: AppLocalizations.of(context).badgeUploading(count),
|
|
|
|
|
|
child: Badge.count(count: count, child: Icon(icon)),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-21 17:20:43 +08:00
|
|
|
|
/// 设置页(UI-01 §4.5 分组重构):账号 / 语言 / 安全(改密 + 退出)/
|
|
|
|
|
|
/// 上传帮助 / 关于(版本)。退出登录确认弹窗明确「本机任务保留,重新
|
|
|
|
|
|
/// 登录后继续」——不承诺退出后后台继续上传。
|
2026-09-19 01:19:57 +08:00
|
|
|
|
class SettingsTab extends ConsumerWidget {
|
2026-09-19 00:22:04 +08:00
|
|
|
|
const SettingsTab({super.key});
|
|
|
|
|
|
|
2026-09-19 05:00:11 +08:00
|
|
|
|
/// 档位 → 展示名(语言名固定以自身语言书写,不随当前界面语言变化)。
|
|
|
|
|
|
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)),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-21 17:20:43 +08:00
|
|
|
|
/// 退出确认:明确本地任务保留、重新登录后继续(不承诺后台继续上传)。
|
|
|
|
|
|
Future<void> _confirmLogout(BuildContext context, WidgetRef ref) async {
|
|
|
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
|
|
|
final confirmed = await showDialog<bool>(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
builder: (dialogContext) => AlertDialog(
|
|
|
|
|
|
title: Text(l10n.logoutConfirmTitle),
|
|
|
|
|
|
content: Text(l10n.logoutConfirmBody),
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
onPressed: () => Navigator.of(dialogContext).pop(false),
|
|
|
|
|
|
child: Text(l10n.cancel),
|
|
|
|
|
|
),
|
|
|
|
|
|
FilledButton(
|
|
|
|
|
|
onPressed: () => Navigator.of(dialogContext).pop(true),
|
|
|
|
|
|
child: Text(l10n.logout),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (confirmed != true || !context.mounted) return;
|
|
|
|
|
|
await _logout(context, ref);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-19 01:19:57 +08:00
|
|
|
|
Future<void> _logout(BuildContext context, WidgetRef ref) async {
|
|
|
|
|
|
// api.logout 尽力而为(服务端撤销失败也照常本地清会话——客户端内已处理)。
|
|
|
|
|
|
await ref.read(apiClientProvider).logout();
|
2026-09-19 04:47:31 +08:00
|
|
|
|
// 会话账号失效 → 引擎 stop(任务保留库内,见 engine_scope.dart)。
|
|
|
|
|
|
await ref.read(sessionAccountProvider.notifier).refresh();
|
2026-09-19 01:19:57 +08:00
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil('/login', (route) => false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-19 00:22:04 +08:00
|
|
|
|
@override
|
2026-09-19 01:19:57 +08:00
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2026-09-19 00:22:04 +08:00
|
|
|
|
final l10n = AppLocalizations.of(context);
|
2026-09-21 17:20:43 +08:00
|
|
|
|
final theme = Theme.of(context);
|
2026-09-19 05:00:11 +08:00
|
|
|
|
final choice = ref.watch(localeSettingsProvider);
|
2026-09-21 17:20:43 +08:00
|
|
|
|
final account = ref.watch(sessionAccountProvider).value;
|
2026-09-19 00:22:04 +08:00
|
|
|
|
return Scaffold(
|
|
|
|
|
|
appBar: AppBar(title: Text(l10n.settings)),
|
|
|
|
|
|
body: ListView(
|
2026-09-21 17:20:43 +08:00
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: kSpace8)
|
|
|
|
|
|
.copyWith(bottom: kSpace16),
|
2026-09-19 00:22:04 +08:00
|
|
|
|
children: [
|
2026-09-21 17:20:43 +08:00
|
|
|
|
// ── 账号 ────────────────────────────────────────────────
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, kSpace16, kSpace16, kSpace8,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: SectionHeader(title: l10n.settingsSectionAccount),
|
|
|
|
|
|
),
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.person_outline),
|
|
|
|
|
|
title: Text(account ?? l10n.notSet),
|
|
|
|
|
|
subtitle: Text(l10n.settingsSignedInAccount),
|
|
|
|
|
|
),
|
|
|
|
|
|
// ── 语言 ────────────────────────────────────────────────
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, kSpace16, kSpace16, kSpace8,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: SectionHeader(title: l10n.settingsSectionLanguage),
|
|
|
|
|
|
),
|
|
|
|
|
|
// 分组已名「语言」,行标题直接显示当前档位(避免同名重复)。
|
2026-09-19 00:22:04 +08:00
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.language),
|
2026-09-21 17:20:43 +08:00
|
|
|
|
title: Text(_choiceLabel(l10n, choice)),
|
|
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
2026-09-19 05:00:11 +08:00
|
|
|
|
onTap: () => _pickLocale(context, ref, choice),
|
2026-09-19 00:22:04 +08:00
|
|
|
|
),
|
2026-09-21 17:20:43 +08:00
|
|
|
|
// ── 安全:改密 + 退出(确认后清会话) ────────────────────
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, kSpace16, kSpace16, kSpace8,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: SectionHeader(title: l10n.settingsSectionSecurity),
|
|
|
|
|
|
),
|
2026-09-19 01:19:57 +08:00
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.password_outlined),
|
|
|
|
|
|
title: Text(l10n.passwordChangeTitle),
|
|
|
|
|
|
onTap: () => Navigator.of(context).pushNamed('/password-change'),
|
|
|
|
|
|
),
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.logout),
|
|
|
|
|
|
title: Text(l10n.logout),
|
2026-09-21 17:20:43 +08:00
|
|
|
|
onTap: () => _confirmLogout(context, ref),
|
|
|
|
|
|
),
|
|
|
|
|
|
// ── 上传帮助:系统限制 / 强退 / 网络等待三分态说明 ────────
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, kSpace16, kSpace16, kSpace8,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: SectionHeader(title: l10n.settingsSectionUploadHelp),
|
|
|
|
|
|
),
|
|
|
|
|
|
ExpansionTile(
|
|
|
|
|
|
leading: const Icon(Icons.help_outline),
|
|
|
|
|
|
title: Text(l10n.settingsUploadHelpTitle),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, 0, kSpace16, kSpace16,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
l10n.settingsUploadHelpBody,
|
|
|
|
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
|
|
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
// ── 关于:版本 ──────────────────────────────────────────
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
|
kSpace16, kSpace16, kSpace16, kSpace8,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: SectionHeader(title: l10n.settingsSectionAbout),
|
|
|
|
|
|
),
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.info_outline),
|
|
|
|
|
|
title: Text(l10n.settingsVersion),
|
|
|
|
|
|
trailing: Text(
|
|
|
|
|
|
kAppVersion,
|
|
|
|
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
|
|
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-09-19 01:19:57 +08:00
|
|
|
|
),
|
2026-09-19 00:22:04 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|