Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How AutoFocus Textfield in flutter

I have a problem while developing my app - how can I auto-focus a textfield after completing input on the previous field, without having to click the textfield?

enter image description here

like image 694
Badai Ardiat Avatar asked Feb 16 '26 04:02

Badai Ardiat


1 Answers

Use focusNode property and onEditingComplete event. Event trigger after user click on enter on first textfield, after that focusNode request focus for the second TextField.

For example:

  FocusNode focusNode = FocusNode();

  @override
  Widget build(BuildContext context) => Scaffold(
      body: Column(
        children: <Widget>[
          TextField(
            autofocus: true,
            onEditingComplete: (() => focusNode.requestFocus())
          ),
          TextField(
            focusNode: focusNode,
          )
        ]
      )
    );

More info at: https://flutter.dev/docs/cookbook/forms/focus

like image 191
Rastlyn Avatar answered Feb 18 '26 22:02

Rastlyn