mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
fix: can't quit app
This commit is contained in:
@@ -21,42 +21,42 @@ class PrivateKeyEditPage extends StatefulWidget {
|
||||
|
||||
class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
with AfterLayoutMixin {
|
||||
final nameController = TextEditingController();
|
||||
final keyController = TextEditingController();
|
||||
final pwdController = TextEditingController();
|
||||
final nameNode = FocusNode();
|
||||
final keyNode = FocusNode();
|
||||
final pwdNode = FocusNode();
|
||||
|
||||
late FocusScopeNode focusScope;
|
||||
final _nameController = TextEditingController();
|
||||
final _keyController = TextEditingController();
|
||||
final _pwdController = TextEditingController();
|
||||
final _nameNode = FocusNode();
|
||||
final _keyNode = FocusNode();
|
||||
final _pwdNode = FocusNode();
|
||||
|
||||
late FocusScopeNode _focusScope;
|
||||
late PrivateKeyProvider _provider;
|
||||
late Widget loading;
|
||||
late S s;
|
||||
late S _s;
|
||||
|
||||
Widget _loading = const SizedBox();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_provider = locator<PrivateKeyProvider>();
|
||||
loading = const SizedBox();
|
||||
_loading = const SizedBox();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
s = S.of(context);
|
||||
focusScope = FocusScope.of(context);
|
||||
_s = S.of(context);
|
||||
_focusScope = FocusScope.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(s.edit, style: textSize18),
|
||||
title: Text(_s.edit, style: textSize18),
|
||||
actions: [
|
||||
widget.info != null
|
||||
? IconButton(
|
||||
tooltip: s.delete,
|
||||
tooltip: _s.delete,
|
||||
onPressed: () {
|
||||
_provider.delInfo(widget.info!);
|
||||
Navigator.of(context).pop();
|
||||
@@ -69,48 +69,48 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
padding: const EdgeInsets.all(13),
|
||||
children: [
|
||||
TextField(
|
||||
controller: nameController,
|
||||
controller: _nameController,
|
||||
keyboardType: TextInputType.text,
|
||||
focusNode: nameNode,
|
||||
onSubmitted: (_) => focusScope.requestFocus(keyNode),
|
||||
decoration: buildDecoration(s.name, icon: Icons.info),
|
||||
focusNode: _nameNode,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_keyNode),
|
||||
decoration: buildDecoration(_s.name, icon: Icons.info),
|
||||
),
|
||||
TextField(
|
||||
controller: keyController,
|
||||
controller: _keyController,
|
||||
autocorrect: false,
|
||||
minLines: 3,
|
||||
maxLines: 10,
|
||||
keyboardType: TextInputType.text,
|
||||
focusNode: keyNode,
|
||||
onSubmitted: (_) => focusScope.requestFocus(pwdNode),
|
||||
focusNode: _keyNode,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_pwdNode),
|
||||
enableSuggestions: false,
|
||||
decoration: buildDecoration(s.privateKey, icon: Icons.vpn_key),
|
||||
decoration: buildDecoration(_s.privateKey, icon: Icons.vpn_key),
|
||||
),
|
||||
TextField(
|
||||
controller: pwdController,
|
||||
controller: _pwdController,
|
||||
autocorrect: false,
|
||||
keyboardType: TextInputType.text,
|
||||
focusNode: pwdNode,
|
||||
focusNode: _pwdNode,
|
||||
obscureText: true,
|
||||
decoration: buildDecoration(s.pwd, icon: Icons.password),
|
||||
decoration: buildDecoration(_s.pwd, icon: Icons.password),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.1),
|
||||
loading
|
||||
_loading
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
tooltip: s.save,
|
||||
tooltip: _s.save,
|
||||
onPressed: () async {
|
||||
final name = nameController.text;
|
||||
final key = keyController.text.trim();
|
||||
final pwd = pwdController.text;
|
||||
final name = _nameController.text;
|
||||
final key = _keyController.text.trim();
|
||||
final pwd = _pwdController.text;
|
||||
if (name.isEmpty || key.isEmpty) {
|
||||
showSnackBar(context, Text(s.fieldMustNotEmpty));
|
||||
showSnackBar(context, Text(_s.fieldMustNotEmpty));
|
||||
return;
|
||||
}
|
||||
FocusScope.of(context).unfocus();
|
||||
setState(() {
|
||||
loading = const SizedBox(
|
||||
_loading = const SizedBox(
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
@@ -126,7 +126,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
haveErr = true;
|
||||
} finally {
|
||||
setState(() {
|
||||
loading = const SizedBox();
|
||||
_loading = const SizedBox();
|
||||
});
|
||||
}
|
||||
if (haveErr) return;
|
||||
@@ -145,9 +145,9 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
@override
|
||||
void afterFirstLayout(BuildContext context) {
|
||||
if (widget.info != null) {
|
||||
nameController.text = widget.info!.id;
|
||||
keyController.text = widget.info!.privateKey;
|
||||
pwdController.text = widget.info!.password;
|
||||
_nameController.text = widget.info!.id;
|
||||
_keyController.text = widget.info!.privateKey;
|
||||
_pwdController.text = widget.info!.password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user