GestureDetector can’t detect touch action on free space

Issue

I’d like to make all the free spase in a widget clicable i.e. all the free space in the raw

GestureDetector(
    onTap: () {
      Navigator.push(
        ...
      );
    },
    child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SampleImage(image1),
          Expanded(
            child: Text('some text'),
          ),
        ],
      ),
)

But some free space still isn’t clicable.

enter image description here

How to achive that?

Solution

From docs it says

By default a GestureDetector with an invisible child ignores touches;
this behavior can be controlled with [behavior].

That’s why that empty space doen’t catch a touch action.

Adding behavior property with opaque enum should solve the issue.

GestureDetector(
    behavior: HitTestBehavior.opaque,

Answered By – thinker

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *