mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat.
- add FocusNode and onSubmitted to TextField
This commit is contained in:
@@ -29,6 +29,7 @@ class _AptManagePageState extends State<AptManagePage>
|
||||
final greyStyle = const TextStyle(color: Colors.grey);
|
||||
final scrollController = ScrollController();
|
||||
final scrollControllerUpdate = ScrollController();
|
||||
final textController = TextEditingController();
|
||||
final _aptProvider = locator<AptProvider>();
|
||||
late S s;
|
||||
|
||||
@@ -57,10 +58,21 @@ class _AptManagePageState extends State<AptManagePage>
|
||||
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<AptManagePage>
|
||||
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<AptManagePage>
|
||||
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),
|
||||
|
||||
@@ -69,15 +69,16 @@ class BackupPage extends StatelessWidget {
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(37),
|
||||
color: priColor
|
||||
),
|
||||
borderRadius: BorderRadius.circular(37), color: priColor),
|
||||
width: 87,
|
||||
height: 37,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, color: textColor,),
|
||||
Icon(
|
||||
icon,
|
||||
color: textColor,
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Text(text, style: TextStyle(color: textColor)),
|
||||
],
|
||||
|
||||
@@ -24,6 +24,11 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
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<PrivateKeyEditPage>
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
s = S.of(context);
|
||||
focusScope = FocusScope.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -62,6 +68,8 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
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<PrivateKeyEditPage>
|
||||
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<PrivateKeyEditPage>
|
||||
controller: pwdController,
|
||||
autocorrect: false,
|
||||
keyboardType: TextInputType.text,
|
||||
focusNode: pwdNode,
|
||||
obscureText: true,
|
||||
decoration: buildDecoration(s.pwd, icon: Icons.password),
|
||||
),
|
||||
|
||||
@@ -31,6 +31,12 @@ class _ServerEditPageState extends State<ServerEditPage> 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<ServerEditPage> with AfterLayoutMixin {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
s = S.of(context);
|
||||
focusScope = FocusScope.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -89,12 +96,16 @@ class _ServerEditPageState extends State<ServerEditPage> 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<ServerEditPage> 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,
|
||||
|
||||
@@ -21,6 +21,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
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<SnippetEditPage>
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user