gskinnerTeam / flutter_vignettes

A collection of fun Flutter experiments, created by gskinner, in partnership with Google.
https://flutter.gskinner.com
MIT License
4.58k stars 1k forks source link

[ticket_fold] FlatButton onTap inside ticket_fold doesn't trigger #5

Closed ricardogobbo closed 4 years ago

ricardogobbo commented 4 years ago

Steps to reproduce:

  1. Remove barcode image from flight_barcode.dart and add a FlatButton like follows:
FlatButton(
  child: Text("Button"),
  onPressed: () => print("button works"),
)

The onTap function doesnt trigger. The card keeps folding.

masterashu commented 4 years ago

This happens because the FlightBarcode is Wrapped inside a Gesture detector here.

masterashu commented 4 years ago

You can refer here to find how to that behavior.

ricardogobbo commented 4 years ago

That's an unexpected behavior.

Look at this Widget. When I tap on red container, onTap is fired. When I press the button, onPressed is triggered.

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("GestureDetector Test")),
      body: Column(
        children: <Widget>[
          GestureDetector(
            onTap: () => print("gestureDetector onTap"),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Container(
                  color: Colors.red, 
                  height: 200, 
                  child: Text("Gesture"),
                ),
                FlatButton(
                  child: Text("button"), 
                  onPressed: () => print("button onPressed"),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
masterashu commented 4 years ago

In the Flutter documentation here it is mentioned that in Gesture Arena only one of the Gesture is declared as victorious. This might differ from one case to another case. Hence it requires custom GestureDetectors.

ricardogobbo commented 4 years ago

Gesture arena didn't recognize button onPressed gesture.

Gesture arena 48   ❙ ★ Opening new gesture arena.
// GestureDetector's onTap 
Gesture arena 48   ❙ Adding: TapGestureRecognizer#6cdd6(debugOwner: GestureDetector, state: ready, button: 1)
// ListView scroll
Gesture arena 48   ❙ Adding: VerticalDragGestureRecognizer#675e5(start behavior: start)
Gesture arena 48   ❙ Closing with 2 members.
Gesture arena 48   ❙ Rejecting: VerticalDragGestureRecognizer#675e5(start behavior: start)
Gesture arena 48   ❙ Sweeping with 1 member.
Gesture arena 48   ❙ Winner: TapGestureRecognizer#6cdd6(debugOwner: GestureDetector, state: ready, finalPosition: Offset(129.4, 493.4), finalLocalPosition: Offset(129.4, 380.3), button: 1, sent tap down)
esDotDev commented 4 years ago

We've refactored the example to allow for embedded buttons :)