是否可以在TextFormField'hinttext'属性中添加一个图标?
我知道下面显示的内容
InputDecoration(
prefixIcon: Icon(
Icons.lock_outline,
)
)
但是我当前想要的是提示图标
因此,如果用户单击提示,则“ hintText”和“ hintIcon”将消失
有没有办法实现这一目标?谢谢
您应该能够通过使用状态来实现所需的目标。
InputDecoration(
prefixIcon: _showHint ? IconButton(
icon: Icon(
Icons.lock_outline,
),
onPressed: () {
setState(() {
_showHint = false;
});
},
) : Container(),
);
要重置_showHint
,您需要使用FocusNode监听事件。 FocusNode
的文档对此进行了说明。