I have a Textfield set up so when I click on it it clears the value -otherwise you have to delete the current value before you can type a new one. The problem is, when I click, the original hint text can be seen which can be quite confusing since it looks like it's been reset.
So for example, the original hint text shows
25
in the text field, then I input a new value of48
. But if I click again to input a new value once more, the original25
hint text value is displayed again after it clears on focus.
final TextEditingController control;
final Function onchanged;
FocusNode _focusNode;
@override
void initState() {
super.initState();
_focusNode = FocusNode();
_focusNode.addListener(() {
if (_focusNode.hasFocus) control.clear();
});
}
TextField(
focusNode: _focusNode,
controller: control,
onChanged: onchanged,
decoration: InputDecoration(
hintText: hint,
),
),
How can I make it so the hint text updates to the previous value (before it is cleared) so that when clicked it shows the same value? This is normal behaviour in form fields so I would like to achieve this.