mirror of
https://github.com/flutter/flutter
synced 2024-08-24 18:36:03 +00:00
Add hitTestBehavior and rootOverlay to LongPressDraggable constructor… (#146386)
Passes through these two Draggable parameters so that they're usable in LongPressDraggable.
This commit is contained in:
parent
0d6bd20a48
commit
c98d68de42
|
@ -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.
|
||||
|
|
|
@ -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>[];
|
||||
|
|
Loading…
Reference in a new issue