1

How to detect the outside in the image?

To open the drawer I already know its function, but to tap the right side of the drawer I don't know

enter image description here

Any help would be appreciated.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • 3
    Removing the drawer normally works out of the box. Since we don't know what you actually coded, or how your code behaves, we cannot help you. Please provide a [mcve], the behavior you expect and the behavior you observe instead. – nvoigt Aug 21 '20 at 12:12
  • I apologize for the uncertainty of my question because I am a new user, I want when tapping the outside of the drawer a message appears, how do I do it? – Royhan Rahim Aug 21 '20 at 12:18
  • Check this: https://stackoverflow.com/questions/53258939/how-catch-the-opening-and-closing-of-the-drawer-in-flutter – Mobina Aug 21 '20 at 12:47
  • okay i will try it, thanks – Royhan Rahim Aug 21 '20 at 13:09

1 Answers1

0

You can add a global boolean isSideBarOpen and make it true when it opens (best in the onPress() event of the button that opens it). And make sure to set it false again once it closes.

You can add a GestureDetector to the Scaffold like this:

body: GestureDetector(
    behavior: HitTestBehavior.opaque,
    onTap: () {
      if (isSideBarOpen) {
        // sideBar.close();
      }
    }

This checks whether the sideBar is open or not and closes it – with the appropriate code – when you tap anywhere else on the screen.