diff --git a/lib/view/page/apt.dart b/lib/view/page/apt.dart index c93d3803..847515ce 100644 --- a/lib/view/page/apt.dart +++ b/lib/view/page/apt.dart @@ -29,6 +29,7 @@ class _AptManagePageState extends State final greyStyle = const TextStyle(color: Colors.grey); final scrollController = ScrollController(); final scrollControllerUpdate = ScrollController(); + final textController = TextEditingController(); final _aptProvider = locator(); late S s; @@ -57,10 +58,21 @@ class _AptManagePageState extends State return; } + // ignore: prefer_function_declarations_over_variables + Function onSubmitted = () { + if (textController.text == '') { + showRoundDialog(context, s.attention, Text(s.fieldMustNotEmpty), [ + TextButton( + onPressed: () => Navigator.of(context).pop(), child: Text(s.ok)), + ]); + return; + } + Navigator.of(context).pop(); + }; + // ignore: prefer_function_declarations_over_variables PwdRequestFunc onPwdRequest = (lastTime, user) async { if (!mounted) return ''; - final textController = TextEditingController(); await showRoundDialog( context, lastTime ? s.lastTry : (user ?? s.unknown), @@ -68,7 +80,7 @@ class _AptManagePageState extends State controller: textController, keyboardType: TextInputType.visiblePassword, obscureText: true, - onSubmitted: (_) => textController.text.trim(), + onSubmitted: (_) => onSubmitted(), decoration: InputDecoration( labelText: s.pwd, ), @@ -78,18 +90,7 @@ class _AptManagePageState extends State onPressed: () => Navigator.of(context).pop(), child: Text(s.cancel)), TextButton( - onPressed: () { - if (textController.text == '') { - showRoundDialog( - context, s.attention, Text(s.fieldMustNotEmpty), [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text(s.ok)), - ]); - return; - } - Navigator.of(context).pop(); - }, + onPressed: () => onSubmitted(), child: Text( s.ok, style: const TextStyle(color: Colors.red), diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index 798d11c3..21c5d9ef 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -68,21 +68,22 @@ class BackupPage extends StatelessWidget { return GestureDetector( onTap: onTap, child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(37), - color: priColor + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(37), color: priColor), + width: 87, + height: 37, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + icon, + color: textColor, + ), + const SizedBox(width: 7), + Text(text, style: TextStyle(color: textColor)), + ], + ), ), - width: 87, - height: 37, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon(icon, color: textColor,), - const SizedBox(width: 7), - Text(text, style: TextStyle(color: textColor)), - ], - ), - ), ); } diff --git a/lib/view/page/private_key/edit.dart b/lib/view/page/private_key/edit.dart index 032c8db7..223c9974 100644 --- a/lib/view/page/private_key/edit.dart +++ b/lib/view/page/private_key/edit.dart @@ -24,6 +24,11 @@ class _PrivateKeyEditPageState extends State 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; @@ -40,6 +45,7 @@ class _PrivateKeyEditPageState extends State void didChangeDependencies() { super.didChangeDependencies(); s = S.of(context); + focusScope = FocusScope.of(context); } @override @@ -62,6 +68,8 @@ class _PrivateKeyEditPageState extends State TextField( controller: nameController, keyboardType: TextInputType.text, + focusNode: nameNode, + onSubmitted: (_) => focusScope.requestFocus(keyNode), decoration: buildDecoration(s.name, icon: Icons.info), ), TextField( @@ -70,6 +78,8 @@ class _PrivateKeyEditPageState extends State minLines: 3, maxLines: 10, keyboardType: TextInputType.text, + focusNode: keyNode, + onSubmitted: (_) => focusScope.requestFocus(pwdNode), enableSuggestions: false, decoration: buildDecoration(s.privateKey, icon: Icons.vpn_key), ), @@ -77,6 +87,7 @@ class _PrivateKeyEditPageState extends State controller: pwdController, autocorrect: false, keyboardType: TextInputType.text, + focusNode: pwdNode, obscureText: true, decoration: buildDecoration(s.pwd, icon: Icons.password), ), diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index 30a2069a..582466c6 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -31,6 +31,12 @@ class _ServerEditPageState extends State with AfterLayoutMixin { final usernameController = TextEditingController(); final passwordController = TextEditingController(); final keyController = TextEditingController(); + final nameFocus = FocusNode(); + final ipFocus = FocusNode(); + final portFocus = FocusNode(); + final usernameFocus = FocusNode(); + + late FocusScopeNode focusScope; late ServerProvider _serverProvider; @@ -51,6 +57,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { void didChangeDependencies() { super.didChangeDependencies(); s = S.of(context); + focusScope = FocusScope.of(context); } @override @@ -89,12 +96,16 @@ class _ServerEditPageState extends State with AfterLayoutMixin { TextField( controller: nameController, keyboardType: TextInputType.text, + focusNode: nameFocus, + onSubmitted: (_) => focusScope.requestFocus(ipFocus), decoration: buildDecoration(s.name, icon: Icons.info, hint: s.exampleName), ), TextField( controller: ipController, keyboardType: TextInputType.text, + onSubmitted: (_) => focusScope.requestFocus(portFocus), + focusNode: ipFocus, autocorrect: false, enableSuggestions: false, decoration: buildDecoration(s.host, @@ -103,12 +114,15 @@ class _ServerEditPageState extends State with AfterLayoutMixin { TextField( controller: portController, keyboardType: TextInputType.number, + focusNode: portFocus, + onSubmitted: (_) => focusScope.requestFocus(usernameFocus), decoration: buildDecoration(s.port, icon: Icons.format_list_numbered, hint: '22'), ), TextField( controller: usernameController, keyboardType: TextInputType.text, + focusNode: usernameFocus, autocorrect: false, enableSuggestions: false, decoration: buildDecoration(s.user, diff --git a/lib/view/page/snippet/edit.dart b/lib/view/page/snippet/edit.dart index e2b8e1e8..7049d637 100644 --- a/lib/view/page/snippet/edit.dart +++ b/lib/view/page/snippet/edit.dart @@ -21,6 +21,7 @@ class _SnippetEditPageState extends State with AfterLayoutMixin { final nameController = TextEditingController(); final scriptController = TextEditingController(); + final scriptNode = FocusNode(); late SnippetProvider _provider; late S s; @@ -57,11 +58,13 @@ class _SnippetEditPageState extends State TextField( controller: nameController, keyboardType: TextInputType.text, + onSubmitted: (_) => FocusScope.of(context).requestFocus(scriptNode), decoration: buildDecoration(s.name, icon: Icons.info), ), TextField( controller: scriptController, autocorrect: false, + focusNode: scriptNode, minLines: 3, maxLines: 10, keyboardType: TextInputType.text,