Home > front end >  GestureDetector can’t detect touch action on free space
GestureDetector can’t detect touch action on free space

Time:03-28

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?

CodePudding user response:

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,
  • Related