From 6786e62263f83b2e2505b686a49bb2fa69416dc3 Mon Sep 17 00:00:00 2001 From: ZV Team Date: Sun, 25 Oct 2026 19:39:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A8=A1=E7=BB=84/=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E9=A1=B5=E7=A9=BA=E7=8A=B6=E6=80=81=E6=94=B9=E4=B8=BA=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=BC=95=E5=AF=BC=E9=A1=B5=EF=BC=88=E5=B8=A6=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E6=A0=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/widgets/empty_state_page.dart | 64 +++++++++++++++++++++ lib/features/mod_manager/mod_list_page.dart | 40 ++++--------- lib/features/terminal/terminal_page.dart | 11 ++-- 3 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 lib/core/widgets/empty_state_page.dart diff --git a/lib/core/widgets/empty_state_page.dart b/lib/core/widgets/empty_state_page.dart new file mode 100644 index 0000000..68e192e --- /dev/null +++ b/lib/core/widgets/empty_state_page.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; + +import '../../core/l10n/strings.dart'; + +/// 统一的「需要先选服务器 / 未配置」引导空状态页。 +/// 自带 AppBar 标题栏,避免页面看起来空白、引导文字无处安放。 +class EmptyStatePage extends StatelessWidget { + final String title; + final IconData icon; + final String message; + final String? actionLabel; + final VoidCallback? onAction; + + const EmptyStatePage({ + super.key, + required this.title, + required this.icon, + required this.message, + this.actionLabel, + this.onAction, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + return Scaffold( + appBar: AppBar(title: T(title)), + body: Center( + child: Padding( + padding: const EdgeInsets.all(32), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + width: 72, + height: 72, + decoration: BoxDecoration( + color: theme.colorScheme.primary.withOpacity(0.12), + borderRadius: BorderRadius.circular(20), + ), + child: Icon(icon, + size: 36, color: theme.colorScheme.primary), + ), + const SizedBox(height: 16), + Text( + S.t(message), + textAlign: TextAlign.center, + style: theme.textTheme.bodyMedium + ?.copyWith(color: theme.hintColor, height: 1.6), + ), + if (actionLabel != null && onAction != null) ...[ + const SizedBox(height: 20), + FilledButton.tonal( + onPressed: onAction, + child: T(actionLabel!), + ), + ], + ], + ), + ), + ), + ); + } +} diff --git a/lib/features/mod_manager/mod_list_page.dart b/lib/features/mod_manager/mod_list_page.dart index f9664a6..43e9499 100644 --- a/lib/features/mod_manager/mod_list_page.dart +++ b/lib/features/mod_manager/mod_list_page.dart @@ -8,6 +8,7 @@ import 'mod_provider.dart'; import 'mod_detail_page.dart'; import 'dependency_tree_page.dart'; import '../../core/l10n/strings.dart'; +import '../../core/widgets/empty_state_page.dart'; /// 模组/插件管理页:列出服务器 mods / plugins 目录中的 jar 文件, /// 支持上传 / 删除 / 重命名 / 查看详情(M1)。 @@ -54,10 +55,18 @@ class _ModListPageState extends State super.build(context); final server = context.watch().server; if (server == null) { - return const Center(child: T('请先在「服务器」页选择一台服务器')); + return EmptyStatePage( + title: '模组管理', + icon: Icons.extension_outlined, + message: '请先在「服务器」页选择一台服务器', + ); } if (!server.hasSsh) { - return _NoSshHint(serverName: server.name); + return EmptyStatePage( + title: '模组管理', + icon: Icons.extension_outlined, + message: '「${server.name}」未开启 SSH,请在服务器设置中开启后使用模组管理', + ); } final hasWallpaper = context.watch().hasWallpaper; final p = _provider; @@ -228,30 +237,3 @@ class _ModListPageState extends State return '${(bytes / 1024 / 1024).toStringAsFixed(1)} MB'; } } - -class _NoSshHint extends StatelessWidget { - final String serverName; - const _NoSshHint({required this.serverName}); - - @override - Widget build(BuildContext context) { - return Center( - child: Padding( - padding: const EdgeInsets.all(24), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.no_encryption_outlined, size: 56), - const SizedBox(height: 12), - Text(S.f('{0} 未配置 SSH', [serverName])), - const SizedBox(height: 8), - const Text( - '模组管理需要 SSH 连接。请在「服务器」页编辑该服务器,\n开启 SSH 并填写用户名和密码。', - textAlign: TextAlign.center, - ), - ], - ), - ), - ); - } -} diff --git a/lib/features/terminal/terminal_page.dart b/lib/features/terminal/terminal_page.dart index 4fe848b..c572b68 100644 --- a/lib/features/terminal/terminal_page.dart +++ b/lib/features/terminal/terminal_page.dart @@ -7,6 +7,7 @@ import '../../core/services/ssh_shell_service.dart'; import '../../providers/server_provider.dart'; import '../../core/l10n/strings.dart'; +import '../../core/widgets/empty_state_page.dart'; /// SSH 终端页:xterm 终端 + 快捷键栏 + 多服务器会话标签(M3)。 @@ -81,12 +82,10 @@ class _TerminalPageState extends State Widget build(BuildContext context) { super.build(context); if (_sshServers.isEmpty) { - return const Center( - child: Padding( - padding: EdgeInsets.all(24), - child: T('没有配置 SSH 的服务器。\n\n请在「服务器」页编辑服务器,开启 SSH 后即可使用终端。', - textAlign: TextAlign.center), - ), + return const EmptyStatePage( + title: '终端', + icon: Icons.terminal_outlined, + message: '没有配置 SSH 的服务器。\n\n请在「服务器」页编辑服务器,开启 SSH 后即可使用终端。', ); } final hasWallpaper = context.watch().hasWallpaper;