skip to Main Content

I have a SizedBox widget that occupies the whole width of the screen, and it has a child widget that has around 400px of width. When the SizedBox is clicked, I’m calling the Navigator.pop to go back to previous page. but I don’t want that to be called when the child widget is clicked. Currently, when I click the child widget, it also calls the onTap function of the parent widget. How can I prevent that?

GestureDetector(
  onTap: () {
    print("GestureDetector Outer");
    final isDismissible = ModalRoute.of(context)?.barrierDismissible;
    if (isDismissible == true) {
      Navigator.pop(context);
    }
  },
  child: SizedBox(
    width: double.maxFinite,
    child: Row(
      children: [
        SizedBox(
          width: 400,
          child: _content(),
        ),
      ],
    ),
  ),
)

2

Answers


  1. Try with wrapping your child widget in to IgnorePointer widget.

    Login or Signup to reply.
  2. Try this!

    You need to wrap your child widget with gesturedetector. also you can use IgnorePointer widget.

        GestureDetector(
          onTap: () {
            print("GestureDetector Outer");
            final isDismissible =
                ModalRoute.of(context)?.barrierDismissible;
            if (isDismissible == true) {
              Navigator.pop(context);
            }
          },
          child: SizedBox(
            width: double.maxFinite,
            child: Row(
              children: [
                GestureDetector(  // wrap your child widget with gesturedetector or IgnorePointer widget
                  onTap: () {},
                  child: SizedBox(
                    width: 400,
                    child: _content(),
                  ),
                ),
              ],
            ),
          ),
        )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search