UI 体验与启动优化 · 主题色 · Gitea CI/夜间预发布 · 后端安全加固
- 启动:健康检查与设置并行请求,页面按需构建并 Offstage 保活,封面按展示尺寸解码 - UI:模型卡片增加悬停动效、封面渐变遮罩、版本/作者/标签胶囊,空简介占位 - 主题:设置页新增主色调选择(预设 + 自定义 #RRGGBB),前后端持久化并实时生效 - CI:新增 PR 审核流水线(后端编译/自检、Flutter 分析测试、漏洞与密钥扫描、汇总门禁) - CI:新增每晚 21:00(UTC 13:00)预发布流水线,prerelease 且不设为 Latest,先删旧再建新 - 安全:后端新增安全响应头、Host/Origin 校验、写入限流、请求体上限、ID 与设置白名单、错误信息脱敏 - 源:暂时只启用 Xhmcl;GitCode 实现保留但不再调用,旧配置自动迁移
This commit is contained in:
1 parent
3480cbaa5f
commit
ae73eca2c4
15 files changed
+1007
-153
No files matched your search
@@ -152,6 +152,7 @@ class SettingsInfo {
|
||||
SettingsInfo.fromJson(Map<String, dynamic> json)
|
||||
: language = json['language'] as String? ?? 'auto',
|
||||
theme = json['theme'] as String? ?? 'light',
|
||||
accentColor = json['accentColor'] as String? ?? '#8FB6FF',
|
||||
renderFps = (json['renderFps'] as num?)?.toInt() ?? 120,
|
||||
memoryMb = (json['memoryMb'] as num?)?.toInt() ?? 2048,
|
||||
memoryAuto = json['memoryAuto'] as bool? ?? true,
|
||||
@@ -176,6 +177,7 @@ class SettingsInfo {
|
||||
|
||||
final String language;
|
||||
final String theme;
|
||||
final String accentColor;
|
||||
final int renderFps;
|
||||
final int memoryMb;
|
||||
final bool memoryAuto;
|
||||
@@ -200,6 +202,7 @@ class SettingsPatch {
|
||||
const SettingsPatch({
|
||||
this.language,
|
||||
this.theme,
|
||||
this.accentColor,
|
||||
this.renderFps,
|
||||
this.memoryMb,
|
||||
this.memoryAuto,
|
||||
@@ -212,6 +215,7 @@ class SettingsPatch {
|
||||
|
||||
final String? language;
|
||||
final String? theme;
|
||||
final String? accentColor;
|
||||
final int? renderFps;
|
||||
final int? memoryMb;
|
||||
final bool? memoryAuto;
|
||||
@@ -225,6 +229,7 @@ class SettingsPatch {
|
||||
final map = <String, dynamic>{};
|
||||
if (language != null) map['language'] = language;
|
||||
if (theme != null) map['theme'] = theme;
|
||||
if (accentColor != null) map['accentColor'] = accentColor;
|
||||
if (renderFps != null) map['renderFps'] = renderFps;
|
||||
if (memoryMb != null) map['memoryMb'] = memoryMb;
|
||||
if (memoryAuto != null) map['memoryAuto'] = memoryAuto;
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'api_client.dart';
|
||||
import 'i18n.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
/// 外壳状态:后端客户端 + 设置 + 健康状态 + 更新状态条。
|
||||
///
|
||||
@@ -27,16 +28,24 @@ class ShellController extends ChangeNotifier {
|
||||
|
||||
Future<void> bootstrap() async {
|
||||
try {
|
||||
health = await api.health();
|
||||
settings = await api.settings();
|
||||
// 健康检查与设置并行请求:两者互不依赖,串行会白白多等一次网络往返。
|
||||
final healthFuture = api.health();
|
||||
final settingsFuture = api.settings();
|
||||
health = await healthFuture;
|
||||
settings = await settingsFuture;
|
||||
loadError = null;
|
||||
I18n.setLanguage(settings!.language);
|
||||
_applySettings(settings!);
|
||||
} catch (error) {
|
||||
loadError = error.toString();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _applySettings(SettingsInfo value) {
|
||||
I18n.setLanguage(value.language);
|
||||
GcPalette.apply(value.accentColor);
|
||||
}
|
||||
|
||||
void goTo(int value) {
|
||||
if (index == value) return;
|
||||
index = value;
|
||||
@@ -47,7 +56,7 @@ class ShellController extends ChangeNotifier {
|
||||
try {
|
||||
settings = await api.settings();
|
||||
loadError = null;
|
||||
I18n.setLanguage(settings!.language);
|
||||
_applySettings(settings!);
|
||||
} catch (error) {
|
||||
loadError = error.toString();
|
||||
}
|
||||
@@ -58,7 +67,7 @@ class ShellController extends ChangeNotifier {
|
||||
try {
|
||||
settings = await api.saveSettings(patch);
|
||||
loadError = null;
|
||||
I18n.setLanguage(settings!.language);
|
||||
_applySettings(settings!);
|
||||
} catch (error) {
|
||||
loadError = error.toString();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class I18n {
|
||||
'home.settings': '设置',
|
||||
'home.installed': '已安装模型',
|
||||
'home.count': '{0} 个模型',
|
||||
'home.noDescription': '暂无简介',
|
||||
'home.empty': '模型库还是空的',
|
||||
'home.emptyHint': '启动时会自动检查并下载模型。若当前断网:可把模型文件夹放进 .GC/model/ 后重新打开,或联网后在「下载」页点重试。',
|
||||
'home.emptyAction': '去下载模型',
|
||||
@@ -62,6 +63,12 @@ class I18n {
|
||||
'set.title': '设置',
|
||||
'set.subtitle': '模型源、启动时内存分配与本地存储。',
|
||||
'set.general': '通用',
|
||||
'set.appearance': '外观',
|
||||
'set.accent': '主题颜色',
|
||||
'set.accent.desc': '选择启动器的主色调,按钮、滑块与高亮会同步换色。',
|
||||
'set.accent.custom': '自定义颜色',
|
||||
'set.accent.hexHint': '格式 #RRGGBB,例如 #8FB6FF',
|
||||
'set.accent.invalid': '颜色格式无效,请使用 #RRGGBB',
|
||||
'set.language': '界面语言',
|
||||
'set.language.auto': '跟随系统',
|
||||
'set.fps': '渲染帧率',
|
||||
@@ -140,6 +147,7 @@ class I18n {
|
||||
'home.settings': 'Settings',
|
||||
'home.installed': 'Installed models',
|
||||
'home.count': '{0} models',
|
||||
'home.noDescription': 'No description',
|
||||
'home.empty': 'No models yet',
|
||||
'home.emptyHint': 'Models are checked and downloaded on startup. Offline: drop model folders into .GC/model/ and reopen, or retry from the Download page once online.',
|
||||
'home.emptyAction': 'Get models',
|
||||
@@ -179,6 +187,12 @@ class I18n {
|
||||
'set.title': 'Settings',
|
||||
'set.subtitle': 'Model sources, startup memory allocation and local storage.',
|
||||
'set.general': 'General',
|
||||
'set.appearance': 'Appearance',
|
||||
'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',
|
||||
|
||||
@@ -6,6 +6,9 @@ import 'shell.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
void main() {
|
||||
// 桌面端无需异步初始化外部插件:尽早绑定并直接渲染首帧,
|
||||
// 让窗口在引擎就绪后立刻出现,后端探测在外壳里异步进行。
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
runApp(const GcUiApp());
|
||||
}
|
||||
|
||||
@@ -25,14 +28,21 @@ class _GcUiAppState extends State<GcUiApp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 语言与强调色都会触发重建:只重建 MaterialApp 的主题层,
|
||||
// 不触碰页面状态(页面由 ShellPage 自己持有)。
|
||||
return ValueListenableBuilder<String>(
|
||||
valueListenable: I18n.language,
|
||||
builder: (context, language, _) {
|
||||
return MaterialApp(
|
||||
title: 'Morris GC',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildGcTheme(),
|
||||
home: ShellPage(controller: _controller),
|
||||
return ValueListenableBuilder<Color>(
|
||||
valueListenable: GcPalette.accent,
|
||||
builder: (context, accent, _) {
|
||||
return MaterialApp(
|
||||
title: 'Morris GC',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildGcTheme(),
|
||||
home: ShellPage(controller: _controller),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
+387
-92
@@ -344,7 +344,7 @@ class _HomePageViewState extends State<HomePageView> {
|
||||
}
|
||||
}
|
||||
|
||||
class _ModelCard extends StatelessWidget {
|
||||
class _ModelCard extends StatefulWidget {
|
||||
const _ModelCard({
|
||||
required this.model,
|
||||
required this.previewUrl,
|
||||
@@ -359,110 +359,249 @@ class _ModelCard extends StatelessWidget {
|
||||
final VoidCallback onOpenFolder;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
State<_ModelCard> createState() => _ModelCardState();
|
||||
}
|
||||
|
||||
class _ModelCardState extends State<_ModelCard> {
|
||||
bool _hover = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 336,
|
||||
child: GcCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(13)),
|
||||
child: SizedBox(
|
||||
height: 138,
|
||||
width: double.infinity,
|
||||
child: Container(
|
||||
color: const Color(0xFF0B1226),
|
||||
child: model.hasPreview
|
||||
? Image.network(
|
||||
previewUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stack) =>
|
||||
const _PreviewFallback(),
|
||||
)
|
||||
: const _PreviewFallback(),
|
||||
),
|
||||
),
|
||||
final model = widget.model;
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hover = true),
|
||||
onExit: (_) => setState(() => _hover = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 160),
|
||||
curve: Curves.easeOut,
|
||||
width: 336,
|
||||
transform: Matrix4.translationValues(0, _hover ? -3 : 0, 0),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: <BoxShadow>[
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(_hover ? 0.42 : 0.22),
|
||||
blurRadius: _hover ? 26 : 14,
|
||||
offset: Offset(0, _hover ? 10 : 6),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 13, 16, 15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
],
|
||||
),
|
||||
child: GcCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
// 封面:图片 + 底部渐变遮罩 + 播放提示 + 版本徽章。
|
||||
ClipRRect(
|
||||
borderRadius:
|
||||
const BorderRadius.vertical(top: Radius.circular(13)),
|
||||
child: SizedBox(
|
||||
height: 152,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
model.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: GcColors.ink,
|
||||
Container(
|
||||
color: const Color(0xFF0B1226),
|
||||
child: model.hasPreview
|
||||
? Image.network(
|
||||
widget.previewUrl,
|
||||
fit: BoxFit.cover,
|
||||
// 只按展示尺寸解码,避免大图占用内存、拖慢首帧。
|
||||
cacheWidth: 672,
|
||||
errorBuilder: (context, error, stack) =>
|
||||
const _PreviewFallback(),
|
||||
)
|
||||
: const _PreviewFallback(),
|
||||
),
|
||||
const DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: <Color>[
|
||||
Color(0x00000000),
|
||||
Color(0x22000000),
|
||||
Color(0xE60A1226),
|
||||
],
|
||||
stops: <double>[0.45, 0.72, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
model.metaText,
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: GcColors.faint,
|
||||
Positioned(
|
||||
left: 14,
|
||||
right: 14,
|
||||
bottom: 11,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (model.version.isNotEmpty)
|
||||
_CoverPill(
|
||||
text: 'v${model.version}',
|
||||
color: GcColors.accent,
|
||||
),
|
||||
if (model.author.isNotEmpty) ...<Widget>[
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
model.author,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: Colors.white70,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
AnimatedOpacity(
|
||||
opacity: _hover ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 160),
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: GcColors.accent.withOpacity(0.9),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.play_arrow_rounded,
|
||||
size: 20, color: Color(0xFF08101F)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
SizedBox(
|
||||
height: 34,
|
||||
child: Text(
|
||||
model.description,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: GcColors.muted,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 13, 16, 15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
model.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: GcColors.ink,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
model.sizeText,
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: GcColors.faint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
// 简介:固定两行高度,避免卡片高低不齐。
|
||||
SizedBox(
|
||||
height: 34,
|
||||
child: Text(
|
||||
model.description.isEmpty
|
||||
? T('home.noDescription')
|
||||
: model.description,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.4,
|
||||
color: model.description.isEmpty
|
||||
? GcColors.faint
|
||||
: GcColors.muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (model.tags.isNotEmpty) ...<Widget>[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
model.tags.join(' · '),
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: GcColors.faint,
|
||||
if (model.tags.isNotEmpty) ...<Widget>[
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
children: <Widget>[
|
||||
for (final tag in model.tags.take(3))
|
||||
_CoverPill(
|
||||
text: tag,
|
||||
color: GcColors.muted,
|
||||
subtle: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 13),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
FilledButton.icon(
|
||||
onPressed: widget.onLaunch,
|
||||
icon: const Icon(Icons.play_arrow_rounded, size: 17),
|
||||
label: Text(T('home.launch')),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: widget.onOpenFolder,
|
||||
child: Text(T('home.open')),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: widget.onDelete,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: GcColors.danger,
|
||||
),
|
||||
child: Text(T('home.delete')),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
FilledButton(
|
||||
onPressed: onLaunch,
|
||||
child: Text(T('home.launch')),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: onOpenFolder,
|
||||
child: Text(T('home.open')),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: onDelete,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: GcColors.danger,
|
||||
),
|
||||
child: Text(T('home.delete')),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 封面上的小胶囊标签(版本 / 标签)。
|
||||
class _CoverPill extends StatelessWidget {
|
||||
const _CoverPill({
|
||||
required this.text,
|
||||
required this.color,
|
||||
this.subtle = false,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final Color color;
|
||||
final bool subtle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: subtle ? GcColors.surfaceAlt : color.withOpacity(0.14),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(
|
||||
color: subtle ? GcColors.line : color.withOpacity(0.35),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
height: 1.1,
|
||||
color: subtle ? GcColors.faint : color,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -473,12 +612,23 @@ class _PreviewFallback extends StatelessWidget {
|
||||
const _PreviewFallback();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Center(
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: <Color>[Color(0xFF16233C), Color(0xFF0B1226)],
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'◎',
|
||||
style: TextStyle(fontSize: 34, color: Color(0xFF1B2A47)),
|
||||
style: TextStyle(fontSize: 34, color: Color(0xFF24365A)),
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1020,6 +1170,8 @@ class _SettingsPageViewState extends State<SettingsPageView> {
|
||||
const SizedBox(height: 18),
|
||||
_generalCard(settings),
|
||||
const SizedBox(height: 16),
|
||||
_appearanceCard(settings),
|
||||
const SizedBox(height: 16),
|
||||
_memoryCard(settings),
|
||||
const SizedBox(height: 16),
|
||||
_sourcesCard(settings),
|
||||
@@ -1106,6 +1258,149 @@ class _SettingsPageViewState extends State<SettingsPageView> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appearanceCard(SettingsInfo settings) {
|
||||
final current =
|
||||
GcPalette.parseHex(settings.accentColor) ?? GcPalette.defaultAccent;
|
||||
return GcCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
GcSectionTitle(T('set.appearance')),
|
||||
const SizedBox(height: 8),
|
||||
GcHint(T('set.accent.desc')),
|
||||
const SizedBox(height: 14),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: <Widget>[
|
||||
for (final color in GcPalette.presets)
|
||||
_accentSwatch(color, current),
|
||||
_customAccentChip(),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'${T('set.accent')}: ${GcPalette.toHex(current)}',
|
||||
style: const TextStyle(fontSize: 11.5, color: GcColors.faint),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _accentSwatch(Color color, Color current) {
|
||||
// ignore: deprecated_member_use
|
||||
final selected = color.value == current.value;
|
||||
return Tooltip(
|
||||
message: GcPalette.toHex(color),
|
||||
child: GestureDetector(
|
||||
onTap: () => _applyAccent(GcPalette.toHex(color)),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: selected ? Colors.white : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
boxShadow: <BoxShadow>[
|
||||
BoxShadow(
|
||||
color: color.withOpacity(selected ? 0.55 : 0.18),
|
||||
blurRadius: selected ? 14 : 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: selected
|
||||
? const Icon(Icons.check_rounded,
|
||||
size: 19, color: Color(0xFF08101F))
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _customAccentChip() {
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: _pickCustomAccent,
|
||||
child: Container(
|
||||
height: 36,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: GcColors.surfaceAlt,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: GcColors.line),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
const Icon(Icons.colorize_rounded,
|
||||
size: 16, color: GcColors.faint),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
T('set.accent.custom'),
|
||||
style: const TextStyle(fontSize: 11.5, 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.surfaceAlt,
|
||||
title: Text(T('set.accent.custom')),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
style: const TextStyle(color: GcColors.ink),
|
||||
decoration: InputDecoration(
|
||||
hintText: '#8FB6FF',
|
||||
hintStyle: const TextStyle(color: GcColors.faint),
|
||||
helperText: T('set.accent.hexHint'),
|
||||
helperStyle: const TextStyle(color: GcColors.faint, fontSize: 11),
|
||||
),
|
||||
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(
|
||||
@@ -1508,7 +1803,7 @@ class _AboutPageViewState extends State<AboutPageView> {
|
||||
? null
|
||||
: NetworkImage(contributor.avatarUrl!),
|
||||
child: contributor.avatarUrl == null
|
||||
? const Text('◎',
|
||||
? Text('◎',
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: GcColors.accent))
|
||||
: null,
|
||||
|
||||
@@ -31,6 +31,10 @@ class ShellPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ShellPageState extends State<ShellPage> {
|
||||
/// 页面缓存:键为「索引:语言」。同一个页面只构建一次,切走时用
|
||||
/// [Offstage] 保活(不参与布局/绘制),切回来无需重建、状态也不丢。
|
||||
final Map<String, Widget> _pages = <String, Widget>{};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -78,7 +82,27 @@ class _ShellPageState extends State<ShellPage> {
|
||||
);
|
||||
}
|
||||
|
||||
switch (controller.index) {
|
||||
// 只构建当前页;其余已访问页面保留在树上但处于 Offstage。
|
||||
final key = '${controller.index}:${I18n.language.value}';
|
||||
_pages.putIfAbsent(key, () => _buildPage(controller, controller.index));
|
||||
|
||||
final visibleKey = key;
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
for (final entry in _pages.entries)
|
||||
Offstage(
|
||||
offstage: entry.key != visibleKey,
|
||||
child: TickerMode(
|
||||
enabled: entry.key == visibleKey,
|
||||
child: entry.value,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage(ShellController controller, int index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
return DownloadPageView(controller: controller);
|
||||
case 2:
|
||||
@@ -241,7 +265,8 @@ class _UpdateBar extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 9),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
const Text('⟳', style: TextStyle(fontSize: 16, color: GcColors.accent)),
|
||||
Text('⟳',
|
||||
style: TextStyle(fontSize: 16, color: GcColors.accent)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
|
||||
@@ -1,5 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 主题强调色(可在设置页自定义,并持久化到后端 settings.accentColor)。
|
||||
///
|
||||
/// 用 [ValueNotifier] 持有当前颜色:设置页改色后,`main.dart` 监听到变化
|
||||
/// 会重建 `MaterialApp.theme`,所有引用 [GcColors.accent] 的组件随之换色。
|
||||
class GcPalette {
|
||||
GcPalette._();
|
||||
|
||||
/// 默认强调色,与 Avalonia 启动器一致。
|
||||
static const Color defaultAccent = Color(0xFF8FB6FF);
|
||||
|
||||
static final ValueNotifier<Color> accent =
|
||||
ValueNotifier<Color>(defaultAccent);
|
||||
|
||||
/// 设置页可选的预设色板。
|
||||
static const List<Color> presets = <Color>[
|
||||
Color(0xFF8FB6FF), // 极光蓝(默认)
|
||||
Color(0xFF7C6CFF), // 星云紫
|
||||
Color(0xFF4FD1C5), // 湖水青
|
||||
Color(0xFF6BE3A2), // 极光绿
|
||||
Color(0xFFFFC46B), // 暖阳橙
|
||||
Color(0xFFFF8FB1), // 樱粉
|
||||
Color(0xFFFF7A7A), // 珊瑚红
|
||||
Color(0xFFB0BEC5), // 石墨灰
|
||||
];
|
||||
|
||||
/// 把 `#RRGGBB` / `RRGGBB` 解析为颜色;非法返回 null。
|
||||
static Color? parseHex(String? value) {
|
||||
if (value == null) return null;
|
||||
var hex = value.trim();
|
||||
if (hex.startsWith('#')) hex = hex.substring(1);
|
||||
if (hex.length == 8) hex = hex.substring(2); // 忽略 alpha
|
||||
if (hex.length != 6) return null;
|
||||
final parsed = int.tryParse(hex, radix: 16);
|
||||
if (parsed == null) return null;
|
||||
return Color(0xFF000000 | parsed);
|
||||
}
|
||||
|
||||
/// 颜色转 `#RRGGBB`。
|
||||
static String toHex(Color color) {
|
||||
// ignore: deprecated_member_use
|
||||
final rgb = color.value & 0xFFFFFF;
|
||||
return '#${rgb.toRadixString(16).padLeft(6, '0').toUpperCase()}';
|
||||
}
|
||||
|
||||
/// 应用颜色(来自后端设置或用户点选)。
|
||||
static void apply(String? hex) {
|
||||
final color = parseHex(hex);
|
||||
if (color == null) return;
|
||||
// ignore: deprecated_member_use
|
||||
if (accent.value.value != color.value) accent.value = color;
|
||||
}
|
||||
}
|
||||
|
||||
/// 与 Avalonia 启动器一致的深色配色。
|
||||
class GcColors {
|
||||
GcColors._();
|
||||
@@ -9,23 +62,37 @@ class GcColors {
|
||||
static const Color surface = Color(0xFF111C33);
|
||||
static const Color surfaceAlt = Color(0xFF16233C);
|
||||
static const Color line = Color(0xFF1B2740);
|
||||
static const Color accent = Color(0xFF8FB6FF);
|
||||
static const Color accentStrong = Color(0xFF4C7DFF);
|
||||
static const Color ink = Color(0xFFF2F6FF);
|
||||
static const Color muted = Color(0xFFA9B8D4);
|
||||
static const Color faint = Color(0xFF7C90B4);
|
||||
static const Color warn = Color(0xFFFFC46B);
|
||||
static const Color danger = Color(0xFFFF7A7A);
|
||||
static const Color ok = Color(0xFF6BE3A2);
|
||||
|
||||
/// 当前强调色(动态,跟随设置)。
|
||||
static Color get accent => GcPalette.accent.value;
|
||||
|
||||
/// 强调色的加深版本,用于主按钮 / 轨道。
|
||||
static Color get accentStrong => _strongen(accent);
|
||||
|
||||
static Color _strongen(Color color) {
|
||||
final hsl = HSLColor.fromColor(color);
|
||||
return hsl
|
||||
.withSaturation((hsl.saturation + 0.12).clamp(0.0, 1.0))
|
||||
.withLightness((hsl.lightness - 0.10).clamp(0.0, 1.0))
|
||||
.toColor();
|
||||
}
|
||||
}
|
||||
|
||||
ThemeData buildGcTheme() {
|
||||
final base = ThemeData.dark(useMaterial3: true);
|
||||
final accent = GcColors.accent;
|
||||
final accentStrong = GcColors.accentStrong;
|
||||
return base.copyWith(
|
||||
scaffoldBackgroundColor: GcColors.appBg,
|
||||
colorScheme: base.colorScheme.copyWith(
|
||||
primary: GcColors.accentStrong,
|
||||
secondary: GcColors.accent,
|
||||
primary: accentStrong,
|
||||
secondary: accent,
|
||||
surface: GcColors.surface,
|
||||
error: GcColors.danger,
|
||||
),
|
||||
@@ -40,24 +107,24 @@ ThemeData buildGcTheme() {
|
||||
margin: EdgeInsets.zero,
|
||||
),
|
||||
sliderTheme: base.sliderTheme.copyWith(
|
||||
activeTrackColor: GcColors.accentStrong,
|
||||
thumbColor: GcColors.accent,
|
||||
activeTrackColor: accentStrong,
|
||||
thumbColor: accent,
|
||||
inactiveTrackColor: GcColors.line,
|
||||
),
|
||||
switchTheme: SwitchThemeData(
|
||||
thumbColor: WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.selected)
|
||||
? GcColors.accent
|
||||
? accent
|
||||
: GcColors.faint,
|
||||
),
|
||||
trackColor: WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.selected)
|
||||
? GcColors.accentStrong.withOpacity(0.45)
|
||||
? accentStrong.withOpacity(0.45)
|
||||
: GcColors.line,
|
||||
),
|
||||
),
|
||||
progressIndicatorTheme: const ProgressIndicatorThemeData(
|
||||
color: GcColors.accent,
|
||||
progressIndicatorTheme: ProgressIndicatorThemeData(
|
||||
color: accent,
|
||||
linearTrackColor: GcColors.line,
|
||||
),
|
||||
tooltipTheme: const TooltipThemeData(
|
||||
|
||||
Reference in new issue
Block a user