GestureDedector's onTap event not working for Sizedbox
Asked Answered
L

3

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.

Liberati answered 6/9, 2021 at 13:29 Comment(3)
@Nagual sizedbox works, stackoverflow asked me to shorten it when asking the question. SizedBox properties: width: 146.0, height: 170.0,Liberati
Where are you testing it, web or phone device. On web, it is working fine.Shenitashenk
On mobile device not working. Even property of GestureDedector I've tried it withLiberati
E
5

Try to add behavior property of GestureDetector

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: (){},
),
Erdei answered 6/9, 2021 at 13:39 Comment(0)
M
6

you need to specify GestureDetector behaviour

GestureDetector(
  behavior: HitTestBehavior.opaque,
  onTap: (){},
),
Misdeed answered 6/9, 2021 at 13:54 Comment(0)
E
5

Try to add behavior property of GestureDetector

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: (){},
),
Erdei answered 6/9, 2021 at 13:39 Comment(0)
A
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

Ambrosio answered 6/9, 2021 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.