Ferhat37ozkan
Ferhat37ozkan

Reputation: 83

GestureDedector's onTap event not working for Sizedbox

I've got a problem with onTap event for GestureDedector. I tried in card too but not working. When I tap sizedbox nothing happens.

      GestureDetector(
                    onTap: () => GoToPage(),
                    child: SizedBox(
                      child: Card(
                        child: Center(
                            child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "assets/png/icon2.png",
                                width: 64.0,
                              ),
                              ...

Thank you.

Upvotes: 5

Views: 4030

Answers (3)

Mhmd Zawi
Mhmd Zawi

Reputation: 167

By default a GestureDetector with an invisible child ignores touches, this behavior can be controlled with behavior. https://flutter.dev/docs/development/ui/advanced/gestures

Upvotes: 2

Nagual
Nagual

Reputation: 2089

you need to specify GestureDetector behaviour

GestureDetector(
  behavior: HitTestBehavior.opaque,
  onTap: (){},
),

Upvotes: 6

CHP
CHP

Reputation: 202

Try to add behavior property of GestureDetector

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: (){},
),

Upvotes: 5

Related Questions