代码之家  ›  专栏  ›  技术社区  ›  Jiehfeng

如何在代码中启用TextFormField中的图标?

  •  0
  • Jiehfeng  · 技术社区  · 4 年前

    我已将颜色设置为 icon 在一个 TextFormField ,但只有当 TextFormField 重点突出。

    我如何设置它,以便在 setState() 这个 偶像 保持“专注”或有色?

    1 回复  |  直到 4 年前
        1
  •  1
  •   Minjin Gelegdorj    4 年前

    尝试以下操作:

    bool _textIsEmpty = true;
    TextEditingController _controller= TextEditingController();
    ... // rest of your code
    
    TextField(
      controller: _controller,
      decoration: InputDecoration(
        icon: Icon(
          Icons.abc,
          color: _textIsEmpty ? Colors.transparent : Colors.pink,
        ),
      ),
      onChanged: (value) {
        setState(() {
          _textIsEmpty = value.isEmpty;
        });
      },
    ),