From c98d68de4202d96ee5022f593d7e72e3c103ac0a Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Mon, 15 Apr 2024 22:50:11 +0330 Subject: [PATCH] =?UTF-8?q?Add=20hitTestBehavior=20and=20rootOverlay=20to?= =?UTF-8?q?=20LongPressDraggable=20constructor=E2=80=A6=20(#146386)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passes through these two Draggable parameters so that they're usable in LongPressDraggable. --- .../flutter/lib/src/widgets/drag_target.dart | 2 + .../flutter/test/widgets/draggable_test.dart | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/packages/flutter/lib/src/widgets/drag_target.dart b/packages/flutter/lib/src/widgets/drag_target.dart index 3aa856f856..04ca7345d2 100644 --- a/packages/flutter/lib/src/widgets/drag_target.dart +++ b/packages/flutter/lib/src/widgets/drag_target.dart @@ -414,6 +414,8 @@ class LongPressDraggable extends Draggable { super.ignoringFeedbackPointer, this.delay = kLongPressTimeout, super.allowedButtonsFilter, + super.hitTestBehavior, + super.rootOverlay, }); /// Whether haptic feedback should be triggered on drag start. diff --git a/packages/flutter/test/widgets/draggable_test.dart b/packages/flutter/test/widgets/draggable_test.dart index d7d43a3320..0432b8530c 100644 --- a/packages/flutter/test/widgets/draggable_test.dart +++ b/packages/flutter/test/widgets/draggable_test.dart @@ -3101,6 +3101,92 @@ void main() { ); }); + testWidgets('Drag feedback is put on root overlay with [rootOverlay] flag', (WidgetTester tester) async { + final GlobalKey rootNavigatorKey = GlobalKey(); + final GlobalKey childNavigatorKey = GlobalKey(); + // Create a [MaterialApp], with a nested [Navigator], which has the + // [Draggable]. + await tester.pumpWidget(MaterialApp( + navigatorKey: rootNavigatorKey, + home: Column( + children: [ + SizedBox( + height: 200.0, + child: Navigator( + key: childNavigatorKey, + onGenerateRoute: (RouteSettings settings) { + if (settings.name == '/') { + return MaterialPageRoute( + settings: settings, + builder: (BuildContext context) => const LongPressDraggable( + data: 1, + feedback: Text('Dragging'), + rootOverlay: true, + child: Text('Source'), + ), + ); + } + throw UnsupportedError('Unsupported route: $settings'); + }, + ), + ), + DragTarget( + builder: (BuildContext context, List data, List rejects) { + return const SizedBox( + height: 300.0, child: Center(child: Text('Target 1')), + ); + }, + ), + ], + ), + )); + + final Offset firstLocation = tester.getCenter(find.text('Source')); + final TestGesture gesture = + await tester.startGesture(firstLocation, pointer: 7); + await tester.pump(kLongPressTimeout); + + final Offset secondLocation = tester.getCenter(find.text('Target 1')); + await gesture.moveTo(secondLocation); + await tester.pump(); + + // Expect that the feedback widget is a descendant of the root overlay, + // but not a descendant of the child overlay. + expect( + find.descendant( + of: find.byType(Overlay).first, + matching: find.text('Dragging'), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byType(Overlay).last, + matching: find.text('Dragging'), + ), + findsNothing, + ); + }); + + testWidgets('configurable DragTarget hit test behavior', (WidgetTester tester) async { + const HitTestBehavior hitTestBehavior = HitTestBehavior.opaque; + + await tester.pumpWidget( + const MaterialApp( + home: Column( + children: [ + LongPressDraggable( + hitTestBehavior: hitTestBehavior, + feedback: SizedBox(), + child: SizedBox(), + ), + ], + ), + ), + ); + expect(tester.widget(find.descendant(of: find.byType(Column), matching: find.byType(Listener))).behavior, hitTestBehavior); + }); + // Regression test for https://github.com/flutter/flutter/issues/72483 testWidgets('Drag and drop - DragTarget can accept Draggable data', (WidgetTester tester) async { final List accepted = [];