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

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,29 +52,26 @@ 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, __) { return Column(
return Column( children: AnimationConfiguration.toStaggeredList(
children: AnimationConfiguration.toStaggeredList( duration: const Duration(milliseconds: 377),
duration: const Duration(milliseconds: 377), childAnimationBuilder: (widget) => SlideAnimation(
childAnimationBuilder: (widget) => SlideAnimation( verticalOffset: 50.0,
verticalOffset: 50.0, child: FadeInAnimation(
child: FadeInAnimation( child: widget,
child: widget,
),
), ),
children: [ ),
const SizedBox(height: 13), children: [
...pro.servers.map((e) => _buildEachServerCard( const SizedBox(height: 13),
pro.servers[pro.servers.indexOf(e)].status, e.info)) ...pro.servers.map((e) => _buildEachServerCard(
], pro.servers[pro.servers.indexOf(e)].status, e.info))
)); ],
})), ));
), })),
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () => showAddServerDialog(), onPressed: () => showAddServerDialog(),
@@ -166,27 +163,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 ?? '';
TextButton( ipController.text = spi.ip ?? '';
onPressed: () => Navigator.of(context).pop(), portController.text = (spi.port ?? 22).toString();
child: const Text('')), usernameController.text = spi.user ?? '';
TextButton( if (spi.authorization is String) {
onPressed: () { passwordController.text = spi.authorization as String? ?? '';
serverProvider.delServer(spi); } else {
Navigator.of(context).pop(); final auth = spi.authorization as Map;
}, passwordController.text = auth['passphrase'];
child: const Text('')) 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) { Widget _buildEachCardContent(ServerStatus ss, ServerPrivateInfo spi) {
return Card( return Card(
child: Padding( child: InkWell(
padding: const EdgeInsets.all(13), child: Padding(
child: _buildRealServerCard(ss, spi.name ?? ''), padding: const EdgeInsets.all(13),
child: _buildRealServerCard(ss, spi.name ?? ''),
),
onTap: () {},
), ),
); );
} }