refactor(ui): 删除百宝箱页;设置页去掉主题色

- 删除 pages/treasure.dart 与侧栏「百宝箱」入口,用户页从 index 6 前移到 5
- 清理 pages.dart 导出与 i18n 里的 nav.treasure / treasure.* 键
- 设置页移除主题色色板、自定义颜色入口与 _applyAccent 等实现
- 强调色改由用户账号的 theme_color 决定:
  · controller._applySettings 不再应用 settings.accentColor
  · 启动后 _applyUserTheme() 拉一次 /api/user/me 并按 theme_color 上色
  · 退出登录回落到 GcPalette.defaultAccent
- 清理 i18n 中的 set.accent.* 键与 settings.dart 无用的 dart:async 导入
This commit is contained in:
Morris committed 2026-11-21 20:45:25 +08:00
1 parent ecb71ad347
commit 38781c9807
7 files changed
+17 -318

No files matched your search

+16 -1
View File
@@ -67,6 +67,8 @@ class ShellController extends ChangeNotifier {
if (settingsResult != null) {
settings = settingsResult;
_applySettings(settingsResult!);
// 主题色现在归用户账号所有(设置页不再提供),启动时按当前用户恢复
unawaited(_applyUserTheme());
}
if (firstError != null && settingsResult == null) {
@@ -97,10 +99,23 @@ class ShellController extends ChangeNotifier {
void _applySettings(SettingsInfo value) {
I18n.setLanguage(value.language);
GcPalette.apply(value.accentColor);
// 强调色不再来自设置:由用户账号的 theme_color 决定(见 _applyUserTheme)
GcPalette.applyTheme(value.theme);
}
/// 按当前登录用户的 theme_color 应用强调色;未登录时保持默认。
Future<void> applyUserTheme() => _applyUserTheme();
Future<void> _applyUserTheme() async {
try {
final resp = await api.me();
final hex = resp?['theme_color'] as String?;
if (hex != null && hex.isNotEmpty) GcPalette.apply('#$hex');
} catch (_) {
// 后端没起来或未登录:保持当前颜色即可
}
}
void goTo(int value) {
if (index == value) return;
index = value;
-12
View File
@@ -17,7 +17,6 @@ class I18n {
'nav.download': '下载',
'nav.settings': '设置',
'nav.about': '关于',
'nav.treasure': '百宝箱',
'nav.user': '用户',
'home.title': '模型库',
'home.subtitle': '选择模型,用可交互的三维演示讲清自转、公转与四季成因。',
@@ -76,11 +75,6 @@ class I18n {
'set.theme.dark': '深色',
'set.theme.light': '浅色',
'set.theme.system': '跟随系统',
'set.accent': '主题颜色',
'set.accent.desc': '选择启动器的主色调,按钮、滑块与高亮会同步换色。',
'set.accent.custom': '自定义颜色',
'set.accent.hexHint': '格式 #RRGGBB,例如 #8FB6FF',
'set.accent.invalid': '颜色格式无效,请使用 #RRGGBB',
'set.language': '界面语言',
'set.language.auto': '跟随系统',
'set.fps': '渲染帧率',
@@ -218,7 +212,6 @@ class I18n {
'nav.download': 'Download',
'nav.settings': 'Settings',
'nav.about': 'About',
'nav.treasure': 'Treasure',
'nav.user': 'User',
'home.title': 'Model library',
'home.subtitle': 'Pick a model and explain rotation, revolution and the seasons with an interactive 3D scene.',
@@ -277,11 +270,6 @@ class I18n {
'set.theme.dark': 'Dark',
'set.theme.light': 'Light',
'set.theme.system': 'System',
'set.accent': 'Theme color',
'set.accent.desc': 'Pick the launcher accent color; buttons, sliders and highlights follow it.',
'set.accent.custom': 'Custom color',
'set.accent.hexHint': 'Format #RRGGBB, e.g. #8FB6FF',
'set.accent.invalid': 'Invalid color, use #RRGGBB',
'set.language': 'Language',
'set.language.auto': 'System',
'set.fps': 'Render frame rate',
-1
View File
@@ -6,5 +6,4 @@ export 'pages/courseware.dart';
export 'pages/download.dart';
export 'pages/settings.dart';
export 'pages/about.dart';
export 'pages/treasure.dart';
export 'pages/user_page.dart';
-137
View File
@@ -1,5 +1,3 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../api_client.dart';
@@ -248,8 +246,6 @@ class _SettingsPageViewState extends State<SettingsPageView> {
}
Widget _appearanceCard(SettingsInfo settings) {
final current =
GcPalette.parseHex(settings.accentColor) ?? GcPalette.defaultAccent;
return GcCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -287,144 +283,11 @@ class _SettingsPageViewState extends State<SettingsPageView> {
if (mounted) setState(() => _status = T('common.applied'));
},
),
const SizedBox(height: GcSpace.xl),
GcHint(T('set.accent.desc')),
const SizedBox(height: GcSpace.md + 2),
Wrap(
spacing: GcSpace.sm + 2,
runSpacing: GcSpace.sm + 2,
children: <Widget>[
for (final color in GcPalette.presets)
_accentSwatch(color, current),
_customAccentChip(),
],
),
const SizedBox(height: GcSpace.md),
Text(
'${T('set.accent')}: ${GcPalette.toHex(current)}',
style: TextStyle(
fontSize: 11.5,
height: 1.4,
color: GcColors.faint,
),
),
],
),
);
}
Widget _accentSwatch(Color color, Color current) {
final selected = color.value == current.value;
return Tooltip(
message: GcPalette.toHex(color),
child: GestureDetector(
onTap: () => _applyAccent(GcPalette.toHex(color)),
child: Container(
width: 34,
height: 34,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(GcRadius.control),
border: Border.all(
color: selected ? GcColors.ink : Colors.transparent,
width: 2,
),
),
child: selected
? Icon(
Icons.check_rounded,
size: 18,
color: color.computeLuminance() > 0.42
? const Color(0xFF0A1226)
: Colors.white,
)
: null,
),
),
);
}
Widget _customAccentChip() {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: _pickCustomAccent,
child: Container(
height: 34,
padding: const EdgeInsets.symmetric(horizontal: GcSpace.md),
decoration: BoxDecoration(
color: GcColors.surfaceAlt,
borderRadius: BorderRadius.circular(GcRadius.control),
border: Border.all(color: GcColors.line),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.colorize_rounded, size: 16, color: GcColors.faint),
const SizedBox(width: GcSpace.xs + 2),
Text(
T('set.accent.custom'),
style: TextStyle(
fontSize: 12,
height: 1.3,
color: GcColors.muted,
),
),
],
),
),
),
);
}
Future<void> _pickCustomAccent() async {
final controller = TextEditingController(
text: GcPalette.toHex(GcPalette.accent.value),
);
final hex = await showDialog<String>(
context: context,
builder: (context) => AlertDialog(
backgroundColor: GcColors.surface,
title: Text(T('set.accent.custom')),
content: TextField(
controller: controller,
autofocus: true,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(fontSize: 13),
decoration: InputDecoration(
hintText: '#8FB6FF',
helperText: T('set.accent.hexHint'),
),
onSubmitted: (value) => Navigator.of(context).pop(value),
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(T('common.cancel')),
),
FilledButton(
onPressed: () => Navigator.of(context).pop(controller.text),
child: Text(T('common.confirm')),
),
],
),
);
controller.dispose();
if (hex != null) await _applyAccent(hex);
}
Future<void> _applyAccent(String hex) async {
final parsed = GcPalette.parseHex(hex);
if (parsed == null) {
if (mounted) setState(() => _status = T('set.accent.invalid'));
return;
}
final normalized = GcPalette.toHex(parsed);
GcPalette.apply(normalized); // 立即预览
await widget.controller
.saveSettings(SettingsPatch(accentColor: normalized));
if (mounted) setState(() => _status = T('common.applied'));
}
Widget _memoryCard(SettingsInfo settings) {
return GcCard(
child: Column(
-163
View File
@@ -1,163 +0,0 @@
import 'dart:math';
import 'package:flutter/material.dart';
import '../controller.dart';
import '../theme.dart';
import '../i18n.dart';
/// 百宝箱页:今日人品、随机运势等小玩意。
class TreasurePage extends StatefulWidget {
const TreasurePage({super.key, required this.controller});
final ShellController controller;
@override
State<TreasurePage> createState() => _TreasurePageState();
}
class _TreasurePageState extends State<TreasurePage> {
String _fortune = '';
String _luckyColor = '';
String _luckyNumber = '';
bool _loading = false;
final Random _rand = Random();
@override
void initState() {
super.initState();
_refresh();
}
void _refresh() {
setState(() => _loading = true);
// 模拟计算延迟
Future.delayed(const Duration(milliseconds: 400), () {
if (!mounted) return;
final fortunes = <String>[
'今日宜:尝试新事物,突破舒适区。',
'运气不错,适合做重要的决定。',
'财运旺盛,可能会有意外收获。',
'人际和谐,适合合作与沟通。',
'专注当下,好运自然来。',
'保持乐观,今天会有好消息。',
'灵感涌现,适合创作和思考。',
'脚踏实地,一步一个脚印。',
'贵人运旺,多与他人交流。',
'健康第一,注意休息和锻炼。',
];
final colors = <String>[
'红色', '蓝色', '绿色', '金色', '紫色', '橙色', '粉色', '青色',
];
setState(() {
_fortune = fortunes[_rand.nextInt(fortunes.length)];
_luckyColor = colors[_rand.nextInt(colors.length)];
_luckyNumber = '${(_rand.nextInt(99)) + 1}';
_loading = false;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: GcColors.appBg,
body: _loading
? const Center(child: CircularProgressIndicator())
: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// 今日人品卡片
GcCard(
padding: const EdgeInsets.all(GcSpace.xxl),
child: Column(
children: <Widget>[
Icon(
Icons.star_rounded,
size: 48,
color: GcColors.accent,
),
const SizedBox(height: GcSpace.lg),
Text(
T('treasure.fortuneTitle'),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: GcSpace.md),
Text(
_fortune,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
height: 1.5,
color: GcColors.muted,
),
),
],
),
),
const SizedBox(height: GcSpace.lg),
// 幸运信息
Wrap(
spacing: GcSpace.md,
runSpacing: GcSpace.md,
children: <Widget>[
_buildStatCard(
icon: Icons.check_circle_outline_rounded,
label: T('treasure.luckyColor'),
value: _luckyColor,
),
_buildStatCard(
icon: Icons.numbers_rounded,
label: T('treasure.luckyNumber'),
value: _luckyNumber,
),
],
),
const SizedBox(height: GcSpace.xl),
// 刷新按钮
FilledButton.icon(
onPressed: _refresh,
icon: const Icon(Icons.refresh_rounded, size: 18),
label: Text(T('treasure.refresh')),
),
],
),
),
),
);
}
Widget _buildStatCard({
required IconData icon,
required String label,
required String value,
}) {
return GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Column(
children: <Widget>[
Icon(icon, size: 28, color: GcColors.accent),
const SizedBox(height: GcSpace.sm),
Text(
label,
style: TextStyle(fontSize: 12, color: GcColors.muted),
),
const SizedBox(height: GcSpace.xs),
Text(
value,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
],
),
);
}
}
+1 -1
View File
@@ -169,7 +169,7 @@ class _UserPageState extends State<UserPage> {
_user = null;
_fortune = null;
});
GcPalette.apply('#${ThemeColor.defaultHex}');
GcPalette.accent.value = GcPalette.defaultAccent;
_toast(T('user.logoutDone'));
}
-3
View File
@@ -20,7 +20,6 @@ const List<_NavItem> _navItems = <_NavItem>[
_NavItem(Icons.download_rounded, 'nav.download'),
_NavItem(Icons.tune_rounded, 'nav.settings'),
_NavItem(Icons.info_outline_rounded, 'nav.about'),
_NavItem(Icons.auto_awesome_rounded, 'nav.treasure'),
_NavItem(Icons.person_rounded, 'nav.user'),
];
@@ -148,8 +147,6 @@ class _ShellPageState extends State<ShellPage> {
case 4:
return AboutPageView(controller: controller);
case 5:
return TreasurePage(controller: controller);
case 6:
return UserPage(controller: controller);
default:
return HomePageView(controller: controller);