0

I have a TextFormField which is empty by default. I'm trying to handle the change when the user finishes editing the field (i don't have a confirm button) How to trigger a function when the TextFormField loses focus ?

KarimHachicha
  • 121
  • 10
  • Does this answer your question? [How to listen focus change in flutter?](https://stackoverflow.com/questions/47965141/how-to-listen-focus-change-in-flutter) – Basel Abuhadrous Apr 03 '22 at 21:04

2 Answers2

0

You can add a FocusNode to the field and add a listener to it, within the listener you can know if it gains/loses focus.

refer to How to listen focus change in flutter?

Basel Abuhadrous
  • 1,444
  • 1
  • 14
  • 30
0

When you say TextFormField loses focus, I am assuming that whenever the user clicks anywhere other than the TextFormField on the screen, the TextFormField loses focus.

In that case, you can wrap the entire widget with a GestureDetector and inside the onTap function

GestureDetector(
  onTap: (){}, //call the function here
);
Samia Ashraf
  • 195
  • 5