This commit is contained in:
parent
2e01eef5aa
commit
bf097eec87
@ -524,9 +524,12 @@ class _DragTargetState<T> extends State<DragTarget<T>> {
|
||||
_candidateAvatars.add(avatar);
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
setState(() {
|
||||
_rejectedAvatars.add(avatar);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
_rejectedAvatars.add(avatar);
|
||||
return false;
|
||||
}
|
||||
|
||||
void didLeave(_DragAvatar<dynamic> avatar) {
|
||||
|
@ -972,6 +972,144 @@ void main() {
|
||||
Offset(secondLocation.dx, secondLocation.dy - firstLocation.dy)));
|
||||
});
|
||||
|
||||
testWidgets('Drag and drop - DragTarget rebuilds with and without rejected data when a rejected draggable enters and leaves', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Column(
|
||||
children: <Widget>[
|
||||
const Draggable<int>(
|
||||
data: 1,
|
||||
child: Text('Source'),
|
||||
feedback: Text('Dragging'),
|
||||
),
|
||||
DragTarget<int>(
|
||||
builder:
|
||||
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
child: rejects.isNotEmpty
|
||||
? const Text('Rejected')
|
||||
: const Text('Target'),
|
||||
);
|
||||
},
|
||||
onWillAccept: (int data) => false,
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
final Offset firstLocation = tester.getTopLeft(find.text('Source'));
|
||||
final TestGesture gesture =
|
||||
await tester.startGesture(firstLocation, pointer: 7);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
final Offset secondLocation = tester.getCenter(find.text('Target'));
|
||||
await gesture.moveTo(secondLocation);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsNothing);
|
||||
expect(find.text('Rejected'), findsOneWidget);
|
||||
|
||||
await gesture.moveTo(firstLocation);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
});
|
||||
|
||||
|
||||
testWidgets('Drag and drop - Can drag and drop over a non-accepting target multiple times', (WidgetTester tester) async {
|
||||
int numberOfTimesOnDraggableCanceledCalled = 0;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Column(
|
||||
children: <Widget>[
|
||||
Draggable<int>(
|
||||
data: 1,
|
||||
child: const Text('Source'),
|
||||
feedback: const Text('Dragging'),
|
||||
onDraggableCanceled: (Velocity velocity, Offset offset) {
|
||||
numberOfTimesOnDraggableCanceledCalled++;
|
||||
},
|
||||
),
|
||||
DragTarget<int>(
|
||||
builder:
|
||||
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
child: rejects.isNotEmpty
|
||||
? const Text('Rejected')
|
||||
: const Text('Target'),
|
||||
);
|
||||
},
|
||||
onWillAccept: (int data) => false,
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
final Offset firstLocation = tester.getTopLeft(find.text('Source'));
|
||||
final TestGesture gesture =
|
||||
await tester.startGesture(firstLocation, pointer: 7);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
final Offset secondLocation = tester.getCenter(find.text('Target'));
|
||||
await gesture.moveTo(secondLocation);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsNothing);
|
||||
expect(find.text('Rejected'), findsOneWidget);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
expect(numberOfTimesOnDraggableCanceledCalled, 1);
|
||||
|
||||
// Drag and drop the Draggable onto the Target a second time.
|
||||
final TestGesture secondGesture =
|
||||
await tester.startGesture(firstLocation, pointer: 7);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
await secondGesture.moveTo(secondLocation);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsNothing);
|
||||
expect(find.text('Rejected'), findsOneWidget);
|
||||
|
||||
await secondGesture.up();
|
||||
await tester.pump();
|
||||
|
||||
expect(numberOfTimesOnDraggableCanceledCalled, 2);
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Drag and drop - onDragCompleted not called if dropped on non-accepting target', (WidgetTester tester) async {
|
||||
final List<int> accepted = <int>[];
|
||||
bool onDragCompletedCalled = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user