如何在Flutter中为文本字段自动显示键盘 [英] How to show the Keyboard automatically for a Textfield in Flutter

查看:133
本文介绍了如何在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)

这篇关于如何在Flutter中为文本字段自动显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆