diff --git a/lib/features/dashboard/dashboard_page.dart b/lib/features/dashboard/dashboard_page.dart index d6eed01..1dd0d0c 100644 --- a/lib/features/dashboard/dashboard_page.dart +++ b/lib/features/dashboard/dashboard_page.dart @@ -75,6 +75,47 @@ class _DashboardPageState extends State { _refreshAll(); } + /// 服务器卡片菜单:编辑 / 删除。 + Future _onServerAction(BuildContext context, ServerConfig s, String action) async { + final serverProvider = context.read(); + final rconProvider = context.read(); + final holder = context.read(); + if (action == 'edit') { + final updated = await showDialog( + context: context, + builder: (_) => ServerFormDialog(existingServer: s), + ); + if (updated == null || !mounted) return; + await serverProvider.updateServer(updated); + // 若编辑的是当前选中服务器,刷新选中引用 + if (holder.server?.id == updated.id) holder.select(updated); + _refreshAll(); + return; + } + if (action == 'delete') { + final confirmed = await showDialog( + context: context, + builder: (_) => AlertDialog( + title: const Text('删除服务器'), + content: Text('确定要删除「${s.name}」吗?仅删除本应用中的连接配置,不影响服务器本身。'), + actions: [ + TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('取消')), + FilledButton( + style: FilledButton.styleFrom(backgroundColor: Colors.red), + onPressed: () => Navigator.pop(context, true), + child: const Text('删除'), + ), + ], + ), + ); + if (confirmed != true || !mounted) return; + await serverProvider.removeServer(s.id); + rconProvider.disposeServer(s.id); + if (holder.server?.id == s.id) holder.select(null); + setState(() => _status.remove(s.id)); + } + } + /// 断线提醒:页面内 SnackBar + 顶部全局提示。 void _showDisconnectAlert(String serverName) { final nav = navigatorKey.currentContext; @@ -227,7 +268,19 @@ class _DashboardPageState extends State { '${st.tps != null ? " · TPS ${st.tps!.toStringAsFixed(1)}" : ""}' : '离线', ), - trailing: isSel ? const Icon(Icons.check) : null, + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (isSel) const Icon(Icons.check, color: Colors.green), + PopupMenuButton( + onSelected: (a) => _onServerAction(context, s, a), + itemBuilder: (_) => const [ + PopupMenuItem(value: 'edit', child: Text('编辑')), + PopupMenuItem(value: 'delete', child: Text('删除')), + ], + ), + ], + ), onTap: () { holder.select(s); setState(() {});