Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide focus to TextField in Flutter

Tags:

flutter

dart

I have been learning flutter for last few days and I encountered a problem while developing my app. So I have a basic form containing all the basic input fields and after a user clicks the submit button the app checks for the validity of the text field. If there is some wrong entry the app moves focus back to the text field.

How can I move focus back to the Text Field?

like image 696
Rishabh Kumar Avatar asked Mar 31 '18 20:03

Rishabh Kumar


People also ask

How do you focus on TextFormField?

By adding a FocusScope and the associated FocusScopeNode , you can easily move the focus to the next TextFormField by passing _node. nextFocus to onEditingComplete . And just as easily, you can call _node. previousFocus() if you need to go back.

What is TextEditingController Flutter?

TextEditingController class Null safety. A controller for an editable text field. Whenever the user modifies a text field with an associated TextEditingController, the text field updates value and the controller notifies its listeners.


1 Answers

var focusNode = FocusNode(); var textField = TextField(focusNode: focusNode);  FocusScope.of(context).requestFocus(focusNode); // or  focusNode.requestFocus(); 

See also

  • https://docs.flutter.io/flutter/widgets/FocusNode-class.html
  • https://flutter.dev/docs/cookbook/forms/focus
like image 148
Günter Zöchbauer Avatar answered Oct 12 '22 00:10

Günter Zöchbauer