服务器状态页支持修改服务器信息

This commit is contained in:
LollipopKit
2021-09-18 19:55:58 +08:00
parent 779876bd4a
commit c00d3c11d6
2 changed files with 71 additions and 40 deletions

View File

@@ -70,7 +70,7 @@ class ServerProvider extends BusyProvider {
} }
Future<void> startAutoRefresh() async { Future<void> startAutoRefresh() async {
Timer.periodic(const Duration(seconds: 7), (_) async { Timer.periodic(const Duration(seconds: 3), (_) async {
await refreshData(); await refreshData();
}); });
} }

View File

@@ -52,8 +52,7 @@ class _ServerPageState extends State<ServerPage>
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
return Scaffold( return Scaffold(
body: GestureDetector( body: SingleChildScrollView(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 7), padding: const EdgeInsets.symmetric(horizontal: 7),
child: AnimationLimiter( child: AnimationLimiter(
child: Consumer<ServerProvider>(builder: (_, pro, __) { child: Consumer<ServerProvider>(builder: (_, pro, __) {
@@ -74,8 +73,6 @@ class _ServerPageState extends State<ServerPage>
)); ));
})), })),
), ),
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () => showAddServerDialog(), onPressed: () => showAddServerDialog(),
tooltip: 'add a server', tooltip: 'add a server',
@@ -167,27 +164,61 @@ class _ServerPageState extends State<ServerPage>
Widget _buildEachServerCard(ServerStatus ss, ServerPrivateInfo spi) { Widget _buildEachServerCard(ServerStatus ss, ServerPrivateInfo spi) {
return GestureDetector( return GestureDetector(
child: _buildEachCardContent(ss, spi), child: _buildEachCardContent(ss, spi),
onLongPress: () => onLongPress: () {
showRoundDialog(context, '是否删除', const Text('删除后无法恢复'), [ 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( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
child: const Text('')), child: const Text('关闭')),
TextButton( TextButton(
onPressed: () { onPressed: () {
serverProvider.delServer(spi); 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(); Navigator.of(context).pop();
}, },
child: const Text('')) child: const Text('连接'))
]), ]);
); });
} }
Widget _buildEachCardContent(ServerStatus ss, ServerPrivateInfo spi) { Widget _buildEachCardContent(ServerStatus ss, ServerPrivateInfo spi) {
return Card( return Card(
child: InkWell(
child: Padding( child: Padding(
padding: const EdgeInsets.all(13), padding: const EdgeInsets.all(13),
child: _buildRealServerCard(ss, spi.name ?? ''), child: _buildRealServerCard(ss, spi.name ?? ''),
), ),
onTap: () {},
),
); );
} }