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 greyStyle = const TextStyle(color: Colors.grey);
|
||||||
final scrollController = ScrollController();
|
final scrollController = ScrollController();
|
||||||
final scrollControllerUpdate = ScrollController();
|
final scrollControllerUpdate = ScrollController();
|
||||||
|
final textController = TextEditingController();
|
||||||
final _aptProvider = locator<AptProvider>();
|
final _aptProvider = locator<AptProvider>();
|
||||||
late S s;
|
late S s;
|
||||||
|
|
||||||
@@ -57,10 +58,21 @@ class _AptManagePageState extends State<AptManagePage>
|
|||||||
return;
|
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
|
// ignore: prefer_function_declarations_over_variables
|
||||||
PwdRequestFunc onPwdRequest = (lastTime, user) async {
|
PwdRequestFunc onPwdRequest = (lastTime, user) async {
|
||||||
if (!mounted) return '';
|
if (!mounted) return '';
|
||||||
final textController = TextEditingController();
|
|
||||||
await showRoundDialog(
|
await showRoundDialog(
|
||||||
context,
|
context,
|
||||||
lastTime ? s.lastTry : (user ?? s.unknown),
|
lastTime ? s.lastTry : (user ?? s.unknown),
|
||||||
@@ -68,7 +80,7 @@ class _AptManagePageState extends State<AptManagePage>
|
|||||||
controller: textController,
|
controller: textController,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
onSubmitted: (_) => textController.text.trim(),
|
onSubmitted: (_) => onSubmitted(),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: s.pwd,
|
labelText: s.pwd,
|
||||||
),
|
),
|
||||||
@@ -78,18 +90,7 @@ class _AptManagePageState extends State<AptManagePage>
|
|||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: Text(s.cancel)),
|
child: Text(s.cancel)),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () => 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();
|
|
||||||
},
|
|
||||||
child: Text(
|
child: Text(
|
||||||
s.ok,
|
s.ok,
|
||||||
style: const TextStyle(color: Colors.red),
|
style: const TextStyle(color: Colors.red),
|
||||||
|
|||||||
@@ -69,15 +69,16 @@ class BackupPage extends StatelessWidget {
|
|||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(37),
|
borderRadius: BorderRadius.circular(37), color: priColor),
|
||||||
color: priColor
|
|
||||||
),
|
|
||||||
width: 87,
|
width: 87,
|
||||||
height: 37,
|
height: 37,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(icon, color: textColor,),
|
Icon(
|
||||||
|
icon,
|
||||||
|
color: textColor,
|
||||||
|
),
|
||||||
const SizedBox(width: 7),
|
const SizedBox(width: 7),
|
||||||
Text(text, style: TextStyle(color: textColor)),
|
Text(text, style: TextStyle(color: textColor)),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
final nameController = TextEditingController();
|
final nameController = TextEditingController();
|
||||||
final keyController = TextEditingController();
|
final keyController = TextEditingController();
|
||||||
final pwdController = TextEditingController();
|
final pwdController = TextEditingController();
|
||||||
|
final nameNode = FocusNode();
|
||||||
|
final keyNode = FocusNode();
|
||||||
|
final pwdNode = FocusNode();
|
||||||
|
|
||||||
|
late FocusScopeNode focusScope;
|
||||||
|
|
||||||
late PrivateKeyProvider _provider;
|
late PrivateKeyProvider _provider;
|
||||||
late Widget loading;
|
late Widget loading;
|
||||||
@@ -40,6 +45,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
s = S.of(context);
|
s = S.of(context);
|
||||||
|
focusScope = FocusScope.of(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -62,6 +68,8 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
TextField(
|
TextField(
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
focusNode: nameNode,
|
||||||
|
onSubmitted: (_) => focusScope.requestFocus(keyNode),
|
||||||
decoration: buildDecoration(s.name, icon: Icons.info),
|
decoration: buildDecoration(s.name, icon: Icons.info),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
@@ -70,6 +78,8 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
minLines: 3,
|
minLines: 3,
|
||||||
maxLines: 10,
|
maxLines: 10,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
focusNode: keyNode,
|
||||||
|
onSubmitted: (_) => focusScope.requestFocus(pwdNode),
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
decoration: buildDecoration(s.privateKey, icon: Icons.vpn_key),
|
decoration: buildDecoration(s.privateKey, icon: Icons.vpn_key),
|
||||||
),
|
),
|
||||||
@@ -77,6 +87,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
controller: pwdController,
|
controller: pwdController,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
focusNode: pwdNode,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: buildDecoration(s.pwd, icon: Icons.password),
|
decoration: buildDecoration(s.pwd, icon: Icons.password),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
final usernameController = TextEditingController();
|
final usernameController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
final keyController = TextEditingController();
|
final keyController = TextEditingController();
|
||||||
|
final nameFocus = FocusNode();
|
||||||
|
final ipFocus = FocusNode();
|
||||||
|
final portFocus = FocusNode();
|
||||||
|
final usernameFocus = FocusNode();
|
||||||
|
|
||||||
|
late FocusScopeNode focusScope;
|
||||||
|
|
||||||
late ServerProvider _serverProvider;
|
late ServerProvider _serverProvider;
|
||||||
|
|
||||||
@@ -51,6 +57,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
s = S.of(context);
|
s = S.of(context);
|
||||||
|
focusScope = FocusScope.of(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -89,12 +96,16 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
focusNode: nameFocus,
|
||||||
|
onSubmitted: (_) => focusScope.requestFocus(ipFocus),
|
||||||
decoration: buildDecoration(s.name,
|
decoration: buildDecoration(s.name,
|
||||||
icon: Icons.info, hint: s.exampleName),
|
icon: Icons.info, hint: s.exampleName),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
controller: ipController,
|
controller: ipController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
onSubmitted: (_) => focusScope.requestFocus(portFocus),
|
||||||
|
focusNode: ipFocus,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
decoration: buildDecoration(s.host,
|
decoration: buildDecoration(s.host,
|
||||||
@@ -103,12 +114,15 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: portController,
|
controller: portController,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
|
focusNode: portFocus,
|
||||||
|
onSubmitted: (_) => focusScope.requestFocus(usernameFocus),
|
||||||
decoration: buildDecoration(s.port,
|
decoration: buildDecoration(s.port,
|
||||||
icon: Icons.format_list_numbered, hint: '22'),
|
icon: Icons.format_list_numbered, hint: '22'),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
controller: usernameController,
|
controller: usernameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
focusNode: usernameFocus,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
decoration: buildDecoration(s.user,
|
decoration: buildDecoration(s.user,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
|||||||
with AfterLayoutMixin {
|
with AfterLayoutMixin {
|
||||||
final nameController = TextEditingController();
|
final nameController = TextEditingController();
|
||||||
final scriptController = TextEditingController();
|
final scriptController = TextEditingController();
|
||||||
|
final scriptNode = FocusNode();
|
||||||
|
|
||||||
late SnippetProvider _provider;
|
late SnippetProvider _provider;
|
||||||
late S s;
|
late S s;
|
||||||
@@ -57,11 +58,13 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
|||||||
TextField(
|
TextField(
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
onSubmitted: (_) => FocusScope.of(context).requestFocus(scriptNode),
|
||||||
decoration: buildDecoration(s.name, icon: Icons.info),
|
decoration: buildDecoration(s.name, icon: Icons.info),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
controller: scriptController,
|
controller: scriptController,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
|
focusNode: scriptNode,
|
||||||
minLines: 3,
|
minLines: 3,
|
||||||
maxLines: 10,
|
maxLines: 10,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
|||||||
Reference in New Issue
Block a user