Skip to content

Commit

Permalink
Add hitTestBehavior and rootOverlay to LongPressDraggable constructor… (
Browse files Browse the repository at this point in the history
flutter#146386)

Passes through these two Draggable parameters so that they're usable in LongPressDraggable.
  • Loading branch information
Amir-P authored Apr 15, 2024
1 parent 0d6bd20 commit c98d68d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/widgets/drag_target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ class LongPressDraggable<T extends Object> extends Draggable<T> {
super.ignoringFeedbackPointer,
this.delay = kLongPressTimeout,
super.allowedButtonsFilter,
super.hitTestBehavior,
super.rootOverlay,
});

/// Whether haptic feedback should be triggered on drag start.
Expand Down
86 changes: 86 additions & 0 deletions packages/flutter/test/widgets/draggable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,92 @@ void main() {
);
});

testWidgets('Drag feedback is put on root overlay with [rootOverlay] flag', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> childNavigatorKey = GlobalKey<NavigatorState>();
// Create a [MaterialApp], with a nested [Navigator], which has the
// [Draggable].
await tester.pumpWidget(MaterialApp(
navigatorKey: rootNavigatorKey,
home: Column(
children: <Widget>[
SizedBox(
height: 200.0,
child: Navigator(
key: childNavigatorKey,
onGenerateRoute: (RouteSettings settings) {
if (settings.name == '/') {
return MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => const LongPressDraggable<int>(
data: 1,
feedback: Text('Dragging'),
rootOverlay: true,
child: Text('Source'),
),
);
}
throw UnsupportedError('Unsupported route: $settings');
},
),
),
DragTarget<int>(
builder: (BuildContext context, List<int?> data, List<dynamic> 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: <Widget>[
LongPressDraggable<int>(
hitTestBehavior: hitTestBehavior,
feedback: SizedBox(),
child: SizedBox(),
),
],
),
),
);
expect(tester.widget<Listener>(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<Object> can accept Draggable<int> data', (WidgetTester tester) async {
final List<Object> accepted = <Object>[];
Expand Down

0 comments on commit c98d68d

Please sign in to comment.