I have set a color to an icon
in a TextFormField
, but the color only comes when the TextFormField
is focused.
How do I set it so that upon a setState()
the icon
stays 'focused' or colored?
CodePudding user response:
try this:
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;
});
},
),