- 新增 GC-UI/:backend(.NET 8 本地 HTTP API + 模型窗口宿主)与 frontend(Flutter 桌面应用) - 前端一套 Dart 代码 + windows/macos 两个原生 runner,共享全部界面逻辑 - 「关于」页新增「源码语言:C#」「前端:Flutter」两行,字段由 /api/about 下发 - 截图脚本覆盖首页/下载/设置/关于/外壳,需要真实后端时用 runAsync 等待请求 - README 补充平台选型理由、接口列表与截图用法
331 lines
9.4 KiB
Dart
331 lines
9.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'controller.dart';
|
|
import 'i18n.dart';
|
|
import 'pages.dart';
|
|
import 'theme.dart';
|
|
|
|
/// 侧边栏导航项。
|
|
class _NavItem {
|
|
const _NavItem(this.icon, this.labelKey);
|
|
|
|
final IconData icon;
|
|
final String labelKey;
|
|
}
|
|
|
|
const List<_NavItem> _navItems = <_NavItem>[
|
|
_NavItem(Icons.grid_view_rounded, 'nav.home'),
|
|
_NavItem(Icons.download_rounded, 'nav.download'),
|
|
_NavItem(Icons.tune_rounded, 'nav.settings'),
|
|
_NavItem(Icons.info_outline_rounded, 'nav.about'),
|
|
];
|
|
|
|
/// 应用外壳:左侧导航 + 右侧内容 + 底部更新状态条。
|
|
class ShellPage extends StatefulWidget {
|
|
const ShellPage({super.key, required this.controller});
|
|
|
|
final ShellController controller;
|
|
|
|
@override
|
|
State<ShellPage> createState() => _ShellPageState();
|
|
}
|
|
|
|
class _ShellPageState extends State<ShellPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
widget.controller.bootstrap();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedBuilder(
|
|
animation: widget.controller,
|
|
builder: (context, _) {
|
|
final controller = widget.controller;
|
|
return Scaffold(
|
|
backgroundColor: GcColors.appBg,
|
|
body: Row(
|
|
children: <Widget>[
|
|
_Sidebar(controller: controller),
|
|
Expanded(
|
|
child: Column(
|
|
children: <Widget>[
|
|
Expanded(child: _content(controller)),
|
|
if (controller.updateBarVisible)
|
|
_UpdateBar(controller: controller),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _content(ShellController controller) {
|
|
if (!controller.backendReady) {
|
|
if (controller.loadError != null) {
|
|
return _BackendDown(controller: controller);
|
|
}
|
|
return const Center(
|
|
child: SizedBox(
|
|
width: 26,
|
|
height: 26,
|
|
child: CircularProgressIndicator(strokeWidth: 2.4),
|
|
),
|
|
);
|
|
}
|
|
|
|
switch (controller.index) {
|
|
case 1:
|
|
return DownloadPageView(controller: controller);
|
|
case 2:
|
|
return SettingsPageView(controller: controller);
|
|
case 3:
|
|
return AboutPageView(controller: controller);
|
|
default:
|
|
return HomePageView(controller: controller);
|
|
}
|
|
}
|
|
}
|
|
|
|
class _Sidebar extends StatelessWidget {
|
|
const _Sidebar({required this.controller});
|
|
|
|
final ShellController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final settings = controller.settings;
|
|
return Container(
|
|
width: 236,
|
|
color: GcColors.sideBg,
|
|
padding: const EdgeInsets.fromLTRB(16, 20, 16, 18),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 26,
|
|
height: 26,
|
|
decoration: BoxDecoration(
|
|
color: GcColors.surfaceAlt,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: const Text(
|
|
'◎',
|
|
style: TextStyle(fontSize: 14, color: GcColors.accent),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
const Expanded(
|
|
child: Text(
|
|
'Morris GC',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
color: GcColors.ink,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
GcHint(T('app.tagline')),
|
|
const SizedBox(height: 26),
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 14, bottom: 6),
|
|
child: Text(
|
|
'MENU',
|
|
style: TextStyle(
|
|
fontSize: 9.5,
|
|
letterSpacing: 1.2,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF4C5F80),
|
|
),
|
|
),
|
|
),
|
|
for (var i = 0; i < _navItems.length; i++)
|
|
_NavButton(
|
|
item: _navItems[i],
|
|
active: controller.index == i,
|
|
onTap: () => controller.goTo(i),
|
|
),
|
|
const Spacer(),
|
|
Container(height: 1, color: GcColors.line),
|
|
const SizedBox(height: 10),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 14),
|
|
child: Text(
|
|
'v${settings?.version ?? '—'}',
|
|
style: const TextStyle(fontSize: 10.5, color: GcColors.faint),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 14, top: 2),
|
|
child: Text(
|
|
settings?.platform ?? '—',
|
|
style: const TextStyle(fontSize: 10, color: Color(0xFF4F6080)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _NavButton extends StatelessWidget {
|
|
const _NavButton({
|
|
required this.item,
|
|
required this.active,
|
|
required this.onTap,
|
|
});
|
|
|
|
final _NavItem item;
|
|
final bool active;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
child: Material(
|
|
color: active ? GcColors.surfaceAlt : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(9),
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(9),
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Icon(
|
|
item.icon,
|
|
size: 16,
|
|
color: active ? GcColors.accent : GcColors.faint,
|
|
),
|
|
const SizedBox(width: 10),
|
|
Text(
|
|
T(item.labelKey),
|
|
style: TextStyle(
|
|
fontSize: 12.5,
|
|
fontWeight: active ? FontWeight.w600 : FontWeight.w400,
|
|
color: active ? GcColors.ink : GcColors.muted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _UpdateBar extends StatelessWidget {
|
|
const _UpdateBar({required this.controller});
|
|
|
|
final ShellController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
color: GcColors.surface,
|
|
border: Border(top: BorderSide(color: GcColors.line)),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 9),
|
|
child: Row(
|
|
children: <Widget>[
|
|
const Text('⟳', style: TextStyle(fontSize: 16, color: GcColors.accent)),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
controller.updateStatus,
|
|
style: const TextStyle(
|
|
fontSize: 12.5,
|
|
fontWeight: FontWeight.w600,
|
|
color: GcColors.ink,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
if (controller.updateDetail.isNotEmpty)
|
|
Text(
|
|
controller.updateDetail,
|
|
style: const TextStyle(fontSize: 11, color: GcColors.faint),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
if (controller.launcherNotice.isNotEmpty)
|
|
Text(
|
|
controller.launcherNotice,
|
|
style: const TextStyle(fontSize: 11, color: GcColors.warn),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (controller.updateBusy)
|
|
const SizedBox(
|
|
width: 130,
|
|
child: LinearProgressIndicator(minHeight: 4),
|
|
),
|
|
const SizedBox(width: 14),
|
|
TextButton(
|
|
onPressed: controller.updateBusy
|
|
? null
|
|
: () => controller.checkUpdate(force: true),
|
|
child: Text(T('update.checkNow')),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _BackendDown extends StatelessWidget {
|
|
const _BackendDown({required this.controller});
|
|
|
|
final ShellController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 520),
|
|
child: GcCard(
|
|
padding: const EdgeInsets.all(28),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
T('common.error'),
|
|
style: const TextStyle(
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w600,
|
|
color: GcColors.ink,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
GcHint(controller.loadError ?? ''),
|
|
const SizedBox(height: 6),
|
|
GcHint('后端地址:${controller.api.baseUrl}'),
|
|
const SizedBox(height: 16),
|
|
FilledButton(
|
|
onPressed: controller.bootstrap,
|
|
child: Text(T('common.retry')),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|