Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the Keyboard automatically for a Textfield in Flutter

I have a TextField in Flutter of which I want to automatically select the text and show the keyboard. I can select the text through a TextEditingController, but even with a FocusNodes requestFocus the keyboard isn't shown, when the Widget opens.

How to automatically open the keyboard for a TextField?

like image 425
relascope Avatar asked Mar 03 '20 15:03

relascope


People also ask

How do you show the keyboard in TextField in Flutter?

TextField is a very common widget in Flutter. When you click on the TextField it opens up the on-screen keyboard. To hide/dismiss the keyboard you have to press the back button in Android and the done button (inside the onscreen keyboard) in iOS.


1 Answers

You can use the autofocus:true property of the TextField:

Whether this text field should focus itself if nothing else is already focused.

So whenever the widget appears on screen, if theres nothing else with the keyboard focus, the focus will automatically be directed to it, thus opening the keyboard.

TextField(TextEditingController: controller, 
         focusNode: focusNode,
         autofocus:true)
like image 66
Naslausky Avatar answered Sep 19 '22 11:09

Naslausky