11import 'package:flutter/material.dart' ;
2+ import 'package:t_samuioto_ssh/terminal_page.dart' ;
23// ignore: unused_import
34import 'package:uuid/uuid.dart' ;
45import 'models/connection_model.dart' ;
56import 'services/storage_service.dart' ;
67import 'quick_connect_dialog.dart' ;
8+ import 'services/ssh_service.dart' ;
9+ //import 'services/storage_service.dart';
710
811class ManageConnectionsPage extends StatefulWidget {
912 const ManageConnectionsPage ({super .key});
@@ -32,7 +35,7 @@ class _ManageConnectionsPageState extends State<ManageConnectionsPage> {
3235void _editConnection (ConnectionInfo connection) {
3336 showDialog (
3437 context: context,
35- builder: (context) => QuickConnectDialog (connection: connection), // 传入连接进行编辑
38+ builder: (context) => QuickConnectDialog (connection: connection),
3639 ).then ((_) => _loadConnections ());
3740}
3841
@@ -41,7 +44,7 @@ void _deleteConnection(ConnectionInfo connection) {
4144 context: context,
4245 builder: (context) => AlertDialog (
4346 title: const Text ('删除连接' ),
44- content: Text ('确定要删除连接 "${connection .name }" 吗?' ),
47+ content: Text ('要删除连接 "${connection .name }" 吗?' ),
4548 actions: [
4649 TextButton (
4750 onPressed: () => Navigator .of (context).pop (),
@@ -65,9 +68,56 @@ void _deleteConnection(ConnectionInfo connection) {
6568 );
6669}
6770
68- void _connectTo (ConnectionInfo connection) {
69- // 应该暂时不需要了
71+ void _connectTo (ConnectionInfo connection) async {
72+ try {
73+ final storageService = StorageService ();
74+ final sshService = SshService ();
75+
76+ // 获取对应的凭证
77+ final credentials = await storageService.getCredentials ();
78+ final credential = credentials.firstWhere (
79+ (c) => c.id == connection.credentialId,
80+ orElse: () => throw Exception ('找不到认证凭证' ),
81+ );
82+
83+ // 显示连接中状态
84+ if (mounted) {
85+ ScaffoldMessenger .of (context).showSnackBar (
86+ const SnackBar (content: Text ('正在连接...' )),
87+ );
88+ }
89+
90+ await sshService.connect (connection, credential);
91+
92+ if (mounted) {
93+ Navigator .of (context).push (
94+ MaterialPageRoute (
95+ builder: (context) => TerminalPage (
96+ connection: connection,
97+ credential: credential,
98+ ),
99+ ),
100+ );
101+ }
102+
103+ } catch (e) {
104+ if (mounted) {
105+ showDialog (
106+ context: context,
107+ builder: (context) => AlertDialog (
108+ title: const Text ('连接失败' ),
109+ content: Text (e.toString ()),
110+ actions: [
111+ TextButton (
112+ onPressed: () => Navigator .of (context).pop (),
113+ child: const Text ('确定' ),
114+ ),
115+ ],
116+ ),
117+ );
118+ }
70119 }
120+ }
71121
72122 @override
73123 Widget build (BuildContext context) {
0 commit comments