I am new in flutter. I am trying to set icon when text changed.
It is not showing icon as I addListner to my controller.
TextEditingController _controller = new TextEditingController();
Defined listner function.
_controller.addListener(() {
setState(() {});
});
TextFormField(
controller: _usernameController,
decoration: InputDecoration(
labelText: 'Username',
suffixIcon: _usernameController.text.length > 0 ? IconButton(
onPressed: () {
//do code for button press
},
icon: Icon(Icons.check, color: Colors.grey)
) : null
),
)
You need to add your listener to your _usernameController not your _controller
_usernameController.addListener(() {
setState(() {});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.