In my textField
I set a condition that when the length of a gets to 10, a suffixIcon
should appear. However, it doesn’t appear until I save the code again. Any help?
My code:
TextField(
inputFormatters: [LengthLimitingTextInputFormatter(10)],
textInputAction: TextInputAction.done,
keyboardType: TextInputType.number,
// onChanged: (value) {
// phone.text = value;
// },
controller: phone,
style: const TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
decoration: InputDecoration(
hintText: "Phone Number...",
hintStyle:
TextStyle(color: Colors.grey.shade600, fontSize: 20),
suffixIcon: phone.text.length == 10
? const Icon(
Icons.done_outline,
color: Colors.green,
size: 40,
)
: null),
),
2
Answers
Reason:-
Its because of the state is not updating when text length is 10
Solution:-
use suffix don’t use suffixIcon for it