I have a TextFormField that has initial value of '0', i want to clear its text when the user clicks on it so that it will be ready for the user input and no need to backspace for the '0'.
In addition, when the user decided not to fill up it will return to '0' value.
I dont know yet where to put the condition
It can be done using many ideas:
The simplest and the fastest way
- Define a hint text
and set it to '0' after submission of the text
field check its text if it has no text, consider 0.
- Define an initial value
for the text field as '0', while using onTap
callback to reset the initial text to empty text when user taps.
- Define a controller
with initial text of '0', while using onTap
callback to reset the initial text.
the second and the third ways will require an additional logic checks to make best UX,
e.g.: if the user has already typed 100 instead of 0 and tapped again (will the 100 become empty space?) but, it was a must to mention those ways, in case of you use labels not hints or even you already have a controller.
Note: don't use initialValue with controllers(Exception will be generated).