I have a TextField that has a controller that has a listener for changes. Like this:
final TextEditingController _oneController = TextEditingController();
@override
void initState() {
super.initState();
_oneController.addListener(_listener);
}
TextField(
controller: _oneController,
),
Where _listener is a function that will dispatch an event that my form has been edited.
This works fine, but whenever you focus on the TextField it triggers this listener to run, even if no changes were made to the text in the field.
Is there a way to stop my listener from being called when the TextField enters focus? I don't want my listener to be called when there are no changes made to the text in my TextField.
_listener- but if you used streams/rxdart you could do that by adding simpledistinct()methodTextEditingControlleris notStringbutTextEditingValue. In addition to text, it contains selection info and some more data. So the value might actually change even when text has not changed. This is the reason why the listener is called on focus. This is also why you are accessing the text using.textand not.valueas you normally do withValueNotifier.