![Flutter实战入门](https://wfqqreader-1252317822.image.myqcloud.com/cover/55/32436055/b_32436055.jpg)
上QQ阅读APP看书,第一时间看更新
3.1.2 文本输入组件(TextField)
TextField组件常用的属性及说明如表3-4所示。
表3-4 TextField属性
![](https://epubservercos.yuewen.com/E5359F/17517093106688906/epubprivate/OEBPS/Images/b3-4-i.jpg?sign=1738869889-pHSFPaZGH4v2TgRHyOMZfhBs7gjzdFV3-0-c24c5766655483422bf0ce55a595380c)
例如,输入框需求如下:圆角边框、文本居中、只能输入英文字符,代码如下:
TextField( decoration: InputDecoration( filled: true, border: OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(20))), ), textAlign: TextAlign.center, inputFormatters: [ WhitelistingTextInputFormatter(RegExp("[a-zA-Z]")), ], ),
运行结果如图3-6所示。
![](https://epubservercos.yuewen.com/E5359F/17517093106688906/epubprivate/OEBPS/Images/t3-6-i.jpg?sign=1738869889-AnvILB2hnseuN3rZVL0jPQkyCVdHfmzW-0-d52b243d7a27546af61dfbbb1b31609e)
图3-6 TextField实现圆角框和英文字符居中
密码输入框,代码如下:
TextField( decoration: InputDecoration(labelText: '请输入密码'), obscureText: true, ),
运行结果如图3-7所示。
![](https://epubservercos.yuewen.com/E5359F/17517093106688906/epubprivate/OEBPS/Images/t3-7-i.jpg?sign=1738869889-rv7Vsi1kYbAjbpZpMDiC5gvqZnLLp4rA-0-90eaefc9030c87dcc213a7e5ac7ea403)
图3-7 密码输入框