Expected results: Parent gesture detector tap event should be fired when parent is clicked and child gesture detector tap event should be fired when child is clicked even when child is clicked immediately after an horizontal scroll.
Actual results: The parent gesture detector tap event is fired when a child gesture detector is clicked immediately after horizontal scrolling. I initially used listview.separated() for the scrollable widget and thought it was due to the list view lazily building the child widgets, but the problem persists even after changing to scrollview. It's the same when the scroll direction is vertical. I have also tried other "clickable" widgets such as inkwells, buttons, and even listeners. Same result.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
print("Parent clicked");
},
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 1)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text(
"Similar Films",
),
],
),
),
SizedBox(
height: (100 / 0.67),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(
100,
(index) => Padding(
padding: EdgeInsets.only(right: 12),
child: GestureDetector(
behavior:
HitTestBehavior.opaque,
onTap: () {
print("Child clicked");
},
child: SizedBox(
width: 100,
height: 100 / 0.67,
child: Container(
decoration: BoxDecoration(
color: Colors.blue.shade100,
),
child: Align(
child: Text("${index+1}")),
),
)),
)),
),
),
)
],
),
),
],
),
),
),
),
),
);
}
}