From c00d3c11d67b4779b2d119cb6901e7e4174c5fa2 Mon Sep 17 00:00:00 2001 From: LollipopKit <2036293523@qq.com> Date: Sat, 18 Sep 2021 19:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E9=A1=B5=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/provider/server.dart | 2 +- lib/view/page/server.dart | 109 ++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 40 deletions(-) diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index e7eb1f04..685a494c 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -70,7 +70,7 @@ class ServerProvider extends BusyProvider { } Future startAutoRefresh() async { - Timer.periodic(const Duration(seconds: 7), (_) async { + Timer.periodic(const Duration(seconds: 3), (_) async { await refreshData(); }); } diff --git a/lib/view/page/server.dart b/lib/view/page/server.dart index 5d37cf2b..08019690 100644 --- a/lib/view/page/server.dart +++ b/lib/view/page/server.dart @@ -52,29 +52,26 @@ class _ServerPageState extends State Widget build(BuildContext context) { super.build(context); return Scaffold( - body: GestureDetector( - child: SingleChildScrollView( - padding: const EdgeInsets.symmetric(horizontal: 7), - child: AnimationLimiter( - child: Consumer(builder: (_, pro, __) { - return Column( - children: AnimationConfiguration.toStaggeredList( - duration: const Duration(milliseconds: 377), - childAnimationBuilder: (widget) => SlideAnimation( - verticalOffset: 50.0, - child: FadeInAnimation( - child: widget, - ), + body: SingleChildScrollView( + padding: const EdgeInsets.symmetric(horizontal: 7), + child: AnimationLimiter( + child: Consumer(builder: (_, pro, __) { + return Column( + children: AnimationConfiguration.toStaggeredList( + duration: const Duration(milliseconds: 377), + childAnimationBuilder: (widget) => SlideAnimation( + verticalOffset: 50.0, + child: FadeInAnimation( + child: widget, ), - children: [ - const SizedBox(height: 13), - ...pro.servers.map((e) => _buildEachServerCard( - pro.servers[pro.servers.indexOf(e)].status, e.info)) - ], - )); - })), - ), - onTap: () => FocusScope.of(context).requestFocus(FocusNode()), + ), + children: [ + const SizedBox(height: 13), + ...pro.servers.map((e) => _buildEachServerCard( + pro.servers[pro.servers.indexOf(e)].status, e.info)) + ], + )); + })), ), floatingActionButton: FloatingActionButton( onPressed: () => showAddServerDialog(), @@ -166,27 +163,61 @@ class _ServerPageState extends State Widget _buildEachServerCard(ServerStatus ss, ServerPrivateInfo spi) { return GestureDetector( - child: _buildEachCardContent(ss, spi), - onLongPress: () => - showRoundDialog(context, '是否删除', const Text('删除后无法恢复'), [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('否')), - TextButton( - onPressed: () { - serverProvider.delServer(spi); - Navigator.of(context).pop(); - }, - child: const Text('是')) - ]), - ); + child: _buildEachCardContent(ss, spi), + onLongPress: () { + nameController.text = spi.name ?? ''; + ipController.text = spi.ip ?? ''; + portController.text = (spi.port ?? 22).toString(); + usernameController.text = spi.user ?? ''; + if (spi.authorization is String) { + passwordController.text = spi.authorization as String? ?? ''; + } else { + final auth = spi.authorization as Map; + passwordController.text = auth['passphrase']; + keyController.text = auth['privateKey']; + } + + showRoundDialog(context, '新建服务器连接', _buildTextInputField(context), [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('关闭')), + TextButton( + onPressed: () { + final authorization = keyController.text.isEmpty + ? passwordController.text + : { + "privateKey": keyController.text, + "passphrase": passwordController.text + }; + serverProvider.updateServer( + spi, + ServerPrivateInfo( + name: nameController.text, + ip: ipController.text, + port: int.parse(portController.text), + user: usernameController.text, + authorization: authorization)); + nameController.clear(); + ipController.clear(); + portController.clear(); + usernameController.clear(); + passwordController.clear(); + keyController.clear(); + Navigator.of(context).pop(); + }, + child: const Text('连接')) + ]); + }); } Widget _buildEachCardContent(ServerStatus ss, ServerPrivateInfo spi) { return Card( - child: Padding( - padding: const EdgeInsets.all(13), - child: _buildRealServerCard(ss, spi.name ?? ''), + child: InkWell( + child: Padding( + padding: const EdgeInsets.all(13), + child: _buildRealServerCard(ss, spi.name ?? ''), + ), + onTap: () {}, ), ); }