- add FocusNode and onSubmitted to TextField
This commit is contained in:
Junyuan Feng
2022-05-23 10:59:10 +08:00
parent 330ff9a621
commit d4368f5084
5 changed files with 58 additions and 28 deletions

View File

@@ -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),