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

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 {
Timer.periodic(const Duration(seconds: 7), (_) async {
Timer.periodic(const Duration(seconds: 3), (_) async {
await refreshData();
});
}

View File

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