0

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!

Joe
  • 311
  • 3
  • 17

1 Answers1

1

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);
MhdBasilE
  • 356
  • 1
  • 4
  • 13
  • Hey, thanks! That works perfectly. Just one question: Why does this require me to return a boolean? This makes it feel as if the puspose of this Widget is something entirely different. I do return true to make it work...but it feel entirely unnnecessary. – Joe Mar 31 '22 at 14:03
  • Actually this is used to make a conformation before exiting from a screen or from entire application, so if the user press ok mean true the application will or screen will close else stay in the same page. Here we don't want to conform the exiting but want to apply a function on closing that's why we always returns true. – MhdBasilE Apr 02 '22 at 04:51