【问题标题】:Flutter, is it possible to add a Icon inside TextFormField 'hinttext' prorperty?Flutter,是否可以在 TextFormField 'hinttext' 属性中添加一个图标?
【发布时间】:2020-08-22 05:29:40
【问题描述】:

是否可以在 TextFormField 'hinttext' 属性中添加图标?

我知道如下所示

InputDecoration(
 prefixIcon: Icon(
  Icons.lock_outline,
    )
 )

但我目前想要的是提示图标

所以如果用户点击提示,那么“hintText”和“hintIcon”就会消失

有没有办法做到这一点?谢谢

【问题讨论】:

  • 您可以使用堆栈小部件来实现此行为

标签: flutter flutter-layout


【解决方案1】:

你应该能够通过使用状态来实现你想要的。

InputDecoration(
  prefixIcon: _showHint ? IconButton(
    icon: Icon(
      Icons.lock_outline,
    ),
    onPressed: () {
      setState(() {
        _showHint = false;
      });
    },
  ) : Container(),
);

要重置_showHint,您需要使用FocusNode 来监听事件。 FocusNode 的文档对此进行了描述。

【讨论】:

    猜你喜欢
    • 2021-10-24
    • 2019-06-25
    • 2020-10-02
    • 1970-01-01
    • 2021-09-06
    • 2011-09-16
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多