opt.: confirm of suspend & etc.

This commit is contained in:
lollipopkit
2023-10-05 17:08:21 +08:00
parent 153bfc191d
commit ef144e27cb
20 changed files with 182 additions and 235 deletions

View File

@@ -111,7 +111,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
onPressed: () {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureToDeleteServer(widget.spi!.name)),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.server}(${widget.spi!.name})',
)),
actions: [
TextButton(
onPressed: () {
@@ -315,14 +317,14 @@ class _ServerEditPageState extends State<ServerEditPage> {
}
void _onSave() async {
if (_ipController.text == '') {
if (_ipController.text.isEmpty) {
context.showSnackBar(l10n.plzEnterHost);
return;
}
if (_keyIdx.value == null && _passwordController.text == '') {
if (_keyIdx.value == null && _passwordController.text.isEmpty) {
final cancel = await context.showRoundDialog<bool>(
title: Text(l10n.attention),
child: Text(l10n.sureNoPwd),
child: Text(l10n.askContinue(l10n.useNoPwd)),
actions: [
TextButton(
onPressed: () => context.pop(false),

View File

@@ -3,6 +3,7 @@ import 'package:circle_chart/circle_chart.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/media_queryx.dart';
@@ -244,35 +245,38 @@ class _ServerPageState extends State<ServerPage>
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () async {
if (Stores.first.showSuspendTip.fetch()) {
await context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.suspendTip),
onPressed: () => _askFor(
func: () async {
if (Stores.first.showSuspendTip.fetch()) {
await context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.suspendTip),
);
Stores.first.showSuspendTip.put(false);
}
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
);
Stores.first.showSuspendTip.put(false);
}
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
);
},
},
msg: 'Suspend ${srv.spi.name}',
),
icon: const Icon(Icons.stop),
tooltip: 'Suspend',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
onPressed: () => _askFor(func: () => srv.client?.execWithPwd(
ShellFunc.shutdown.exec,
context: context,
),
), msg: 'Shutdown ${srv.spi.name}',),
icon: const Icon(Icons.power_off),
tooltip: 'Shutdown',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
onPressed: () => _askFor(func: () => srv.client?.execWithPwd(
ShellFunc.reboot.exec,
context: context,
),
), msg: 'Reboot ${srv.spi.name}',),
icon: const Icon(Icons.restart_alt),
tooltip: 'Reboot',
),
@@ -531,4 +535,20 @@ class _ServerPageState extends State<ServerPage>
}
return 107;
}
void _askFor({required void Function() func, required String msg}) {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.askContinue(msg)),
actions: [
TextButton(
onPressed: () {
context.pop();
func();
},
child: Text(l10n.ok),
),
],
);
}
}