Make Dismissible's HitTestBehavior an argument (#64379)
diff --git a/packages/flutter/lib/src/widgets/dismissible.dart b/packages/flutter/lib/src/widgets/dismissible.dart
index 3105160..799880c 100644
--- a/packages/flutter/lib/src/widgets/dismissible.dart
+++ b/packages/flutter/lib/src/widgets/dismissible.dart
@@ -94,6 +94,7 @@
this.movementDuration = const Duration(milliseconds: 200),
this.crossAxisEndOffset = 0.0,
this.dragStartBehavior = DragStartBehavior.start,
+ this.behavior = HitTestBehavior.opaque,
}) : assert(key != null),
assert(secondaryBackground == null || background != null),
assert(dragStartBehavior != null),
@@ -185,6 +186,11 @@
/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors.
final DragStartBehavior dragStartBehavior;
+ /// How to behave during hit tests.
+ ///
+ /// This defaults to [HitTestBehavior.opaque].
+ final HitTestBehavior behavior;
+
@override
_DismissibleState createState() => _DismissibleState();
}
@@ -574,7 +580,7 @@
onVerticalDragStart: _directionIsXAxis ? null : _handleDragStart,
onVerticalDragUpdate: _directionIsXAxis ? null : _handleDragUpdate,
onVerticalDragEnd: _directionIsXAxis ? null : _handleDragEnd,
- behavior: HitTestBehavior.opaque,
+ behavior: widget.behavior,
child: content,
dragStartBehavior: widget.dragStartBehavior,
);
diff --git a/packages/flutter/test/widgets/dismissible_test.dart b/packages/flutter/test/widgets/dismissible_test.dart
index 44e102f..20e1c7d 100644
--- a/packages/flutter/test/widgets/dismissible_test.dart
+++ b/packages/flutter/test/widgets/dismissible_test.dart
@@ -798,4 +798,73 @@
' handler has fired.\n',
);
});
+
+ testWidgets('Dismissible.behavior should behave correctly during hit testing', (WidgetTester tester) async {
+ bool didReceivePointerDown = false;
+
+ Widget buildStack({Widget child}) {
+ return Directionality(
+ textDirection: TextDirection.ltr,
+ child: Stack(
+ children: <Widget>[
+ Listener(
+ onPointerDown: (_) {
+ didReceivePointerDown = true;
+ },
+ child: Container(
+ width: 100.0,
+ height: 100.0,
+ color: const Color(0xFF00FF00),
+ ),
+ ),
+ child,
+ ],
+ ),
+ );
+ }
+
+ await tester.pumpWidget(
+ buildStack(
+ child: const Dismissible(
+ key: ValueKey<int>(1),
+ child: SizedBox(
+ width: 100.0,
+ height: 100.0,
+ ),
+ ),
+ ),
+ );
+ await tester.tapAt(const Offset(10.0, 10.0));
+ expect(didReceivePointerDown, isFalse);
+
+ Future<void> pumpWidgetTree(HitTestBehavior behavior) {
+ return tester.pumpWidget(
+ buildStack(
+ child: Dismissible(
+ key: const ValueKey<int>(1),
+ behavior: behavior,
+ child: const SizedBox(
+ width: 100.0,
+ height: 100.0,
+ ),
+ ),
+ ),
+ );
+ }
+
+ didReceivePointerDown = false;
+ await pumpWidgetTree(HitTestBehavior.deferToChild);
+ await tester.tapAt(const Offset(10.0, 10.0));
+ expect(didReceivePointerDown, isTrue);
+
+ didReceivePointerDown = false;
+ await pumpWidgetTree(HitTestBehavior.opaque);
+ await tester.tapAt(const Offset(10.0, 10.0));
+ expect(didReceivePointerDown, isFalse);
+
+ didReceivePointerDown = false;
+ await pumpWidgetTree(HitTestBehavior.translucent);
+ await tester.tapAt(const Offset(10.0, 10.0));
+ expect(didReceivePointerDown, isTrue);
+ });
}