Unverified Commit 1a9ea39a authored by TheBiirb's avatar TheBiirb Committed by GitHub

Make Dismissible's HitTestBehavior an argument (#64379)

parent 8ed0ac53
......@@ -94,6 +94,7 @@ class Dismissible extends StatefulWidget {
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 @@ class Dismissible extends StatefulWidget {
/// * [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 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
onVerticalDragStart: _directionIsXAxis ? null : _handleDragStart,
onVerticalDragUpdate: _directionIsXAxis ? null : _handleDragUpdate,
onVerticalDragEnd: _directionIsXAxis ? null : _handleDragEnd,
behavior: HitTestBehavior.opaque,
behavior: widget.behavior,
child: content,
dragStartBehavior: widget.dragStartBehavior,
);
......
......@@ -798,4 +798,73 @@ void main() {
' 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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment