Home > other >  TextFormField Focus Flutter
TextFormField Focus Flutter

Time:04-04

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 ?

CodePudding user response:

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?

CodePudding user response:

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
);
  • Related