5

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.

3 Answers3

5

you need to specify GestureDetector behaviour

GestureDetector(
  behavior: HitTestBehavior.opaque,
  onTap: (){},
),
Nagual
  • 1,576
  • 10
  • 17
  • 27
4

Try to add behavior property of GestureDetector

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: (){},
),
CHP
  • 192
  • 6
2

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

Mhmd Zawi
  • 167
  • 1
  • 11