如何在Flutter中为文本字段自动显示键盘

问题描述:

我在Flutter中有一个 TextField ,我想自动选择文本并显示键盘.我可以通过 TextEditingController 选择文本,但是即使使用 FocusNodes requestFocus,打开小部件时也不会显示键盘.

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.

如何自动打开TextField的键盘?

How to automatically open the keyboard for a TextField?

您可以使用autofocus:true 属性/material/TextField-class.html"rel =" noreferrer> TextField :

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)