Submit data/trigger function when modalsheet is closed

291 Views Asked by At

I'm using a modal sheet with a TextEditingController and a TextField to allow the users to make inputs. When the user submints (presses enter on the keyboard), a function is triggered, the data collected and everything works perfectly. But: If the user clicks outside of the modal sheet, it closes without the onsubmit function being triggered. Can I change that somehow?

In short: I want to treat tapping outside of the modal sheet as if the user hits enter/submits.

Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

wrap the model sheet with WillPopScop widget and onpop you can write your function eg

         WillPopScope(
    onWillPop: () async {
      //enter your function here
      return true;
    },
    child://child);