Merge pull request #3012 from apwilson/leave
Leave all entered targets when finishing.
This commit is contained in:
commit
d61f7809c8
@ -391,7 +391,7 @@ class _DragAvatar<T> extends Drag {
|
|||||||
final _OnDragEnd onDragEnd;
|
final _OnDragEnd onDragEnd;
|
||||||
|
|
||||||
_DragTargetState<T> _activeTarget;
|
_DragTargetState<T> _activeTarget;
|
||||||
List<_DragTargetState<T>> _lastTargets = <_DragTargetState<T>>[];
|
List<_DragTargetState<T>> _enteredTargets = <_DragTargetState<T>>[];
|
||||||
Point _position;
|
Point _position;
|
||||||
Offset _lastOffset;
|
Offset _lastOffset;
|
||||||
OverlayEntry _entry;
|
OverlayEntry _entry;
|
||||||
@ -422,12 +422,12 @@ class _DragAvatar<T> extends Drag {
|
|||||||
List<_DragTargetState<T>> targets = _getDragTargets(result.path).toList();
|
List<_DragTargetState<T>> targets = _getDragTargets(result.path).toList();
|
||||||
|
|
||||||
bool listsMatch = false;
|
bool listsMatch = false;
|
||||||
if (targets.length >= _lastTargets.length && _lastTargets.isNotEmpty) {
|
if (targets.length >= _enteredTargets.length && _enteredTargets.isNotEmpty) {
|
||||||
listsMatch = true;
|
listsMatch = true;
|
||||||
Iterator<_DragTargetState<T>> iterator = targets.iterator;
|
Iterator<_DragTargetState<T>> iterator = targets.iterator;
|
||||||
for (int i = 0; i < _lastTargets.length; i += 1) {
|
for (int i = 0; i < _enteredTargets.length; i += 1) {
|
||||||
iterator.moveNext();
|
iterator.moveNext();
|
||||||
if (iterator.current != _lastTargets[i]) {
|
if (iterator.current != _enteredTargets[i]) {
|
||||||
listsMatch = false;
|
listsMatch = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -439,13 +439,11 @@ class _DragAvatar<T> extends Drag {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Leave old targets.
|
// Leave old targets.
|
||||||
for (int i = 0; i < _lastTargets.length; i += 1)
|
_leaveAllEntered();
|
||||||
_lastTargets[i].didLeave(data);
|
|
||||||
_lastTargets.clear();
|
|
||||||
|
|
||||||
// Enter new targets.
|
// Enter new targets.
|
||||||
_DragTargetState<T> newTarget = targets.firstWhere((_DragTargetState<T> target) {
|
_DragTargetState<T> newTarget = targets.firstWhere((_DragTargetState<T> target) {
|
||||||
_lastTargets.add(target);
|
_enteredTargets.add(target);
|
||||||
return target.didEnter(data);
|
return target.didEnter(data);
|
||||||
},
|
},
|
||||||
orElse: () => null
|
orElse: () => null
|
||||||
@ -466,16 +464,20 @@ class _DragAvatar<T> extends Drag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _leaveAllEntered() {
|
||||||
|
for (int i = 0; i < _enteredTargets.length; i += 1)
|
||||||
|
_enteredTargets[i].didLeave(data);
|
||||||
|
_enteredTargets.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void finish(_DragEndKind endKind, [Velocity velocity]) {
|
void finish(_DragEndKind endKind, [Velocity velocity]) {
|
||||||
bool wasAccepted = false;
|
bool wasAccepted = false;
|
||||||
if (_activeTarget != null) {
|
if (endKind == _DragEndKind.dropped && _activeTarget != null) {
|
||||||
if (endKind == _DragEndKind.dropped && _activeTarget != null) {
|
_activeTarget.didDrop(data);
|
||||||
_activeTarget.didDrop(data);
|
wasAccepted = true;
|
||||||
wasAccepted = true;
|
_enteredTargets.remove(_activeTarget);
|
||||||
} else {
|
|
||||||
_activeTarget.didLeave(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_leaveAllEntered();
|
||||||
_activeTarget = null;
|
_activeTarget = null;
|
||||||
_entry.remove();
|
_entry.remove();
|
||||||
_entry = null;
|
_entry = null;
|
||||||
|
@ -11,30 +11,22 @@ void main() {
|
|||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<int> accepted = <int>[];
|
List<int> accepted = <int>[];
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging')
|
feedback: new Text('Dragging')),
|
||||||
),
|
new DragTarget<int>(builder:
|
||||||
new DragTarget<int>(
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
return new Container(height: 100.0, child: new Text('Target'));
|
||||||
return new Container(
|
}, onAccept: (int data) {
|
||||||
height: 100.0,
|
accepted.add(data);
|
||||||
child: new Text('Target')
|
}),
|
||||||
);
|
]);
|
||||||
},
|
},
|
||||||
onAccept: (int data) {
|
}));
|
||||||
accepted.add(data);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(accepted, isEmpty);
|
expect(accepted, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -74,44 +66,31 @@ void main() {
|
|||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation;
|
Point firstLocation, secondLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging')
|
feedback: new Text('Dragging')),
|
||||||
),
|
new Stack(children: <Widget>[
|
||||||
new Stack(
|
new GestureDetector(
|
||||||
children: <Widget>[
|
behavior: HitTestBehavior.opaque,
|
||||||
new GestureDetector(
|
onTap: () {
|
||||||
behavior: HitTestBehavior.opaque,
|
events.add('tap');
|
||||||
onTap: () {
|
},
|
||||||
events.add('tap');
|
child: new Container(child: new Text('Button'))),
|
||||||
},
|
new DragTarget<int>(builder: (BuildContext context,
|
||||||
child: new Container(
|
List<int> data, List<dynamic> rejects) {
|
||||||
child: new Text('Button')
|
return new IgnorePointer(
|
||||||
)
|
child: new Container(child: new Text('Target')));
|
||||||
),
|
}, onAccept: (int data) {
|
||||||
new DragTarget<int>(
|
events.add('drop');
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
}),
|
||||||
return new IgnorePointer(
|
]),
|
||||||
child: new Container(
|
]);
|
||||||
child: new Text('Target')
|
},
|
||||||
)
|
}));
|
||||||
);
|
|
||||||
},
|
|
||||||
onAccept: (int data) {
|
|
||||||
events.add('drop');
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -172,35 +151,27 @@ void main() {
|
|||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation;
|
Point firstLocation, secondLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new GestureDetector(
|
child: new GestureDetector(
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
events.add('tap');
|
events.add('tap');
|
||||||
},
|
},
|
||||||
child: new Container(
|
child: new Container(child: new Text('Button'))),
|
||||||
child: new Text('Button')
|
feedback: new Text('Dragging')),
|
||||||
)
|
new DragTarget<int>(builder:
|
||||||
),
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
feedback: new Text('Dragging')
|
return new Text('Target');
|
||||||
),
|
}, onAccept: (int data) {
|
||||||
new DragTarget<int>(
|
events.add('drop');
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
}),
|
||||||
return new Text('Target');
|
]);
|
||||||
},
|
},
|
||||||
onAccept: (int data) {
|
}));
|
||||||
events.add('drop');
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Button'), isNotNull);
|
expect(tester.findText('Button'), isNotNull);
|
||||||
@ -224,7 +195,6 @@ void main() {
|
|||||||
tester.pump();
|
tester.pump();
|
||||||
expect(events, equals(<String>['drop']));
|
expect(events, equals(<String>['drop']));
|
||||||
events.clear();
|
events.clear();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -233,27 +203,22 @@ void main() {
|
|||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation;
|
Point firstLocation, secondLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new LongPressDraggable<int>(
|
||||||
new LongPressDraggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging')
|
feedback: new Text('Dragging')),
|
||||||
),
|
new DragTarget<int>(builder:
|
||||||
new DragTarget<int>(
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
return new Text('Target');
|
||||||
return new Text('Target');
|
}, onAccept: (int data) {
|
||||||
},
|
events.add('drop');
|
||||||
onAccept: (int data) {
|
}),
|
||||||
events.add('drop');
|
]);
|
||||||
}
|
},
|
||||||
),
|
}));
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -275,7 +240,6 @@ void main() {
|
|||||||
gesture.up();
|
gesture.up();
|
||||||
tester.pump();
|
tester.pump();
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -284,27 +248,22 @@ void main() {
|
|||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation;
|
Point firstLocation, secondLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging')
|
feedback: new Text('Dragging')),
|
||||||
),
|
new DragTarget<int>(builder:
|
||||||
new DragTarget<int>(
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
return new Text('Target');
|
||||||
return new Text('Target');
|
}, onAccept: (int data) {
|
||||||
},
|
events.add('drop');
|
||||||
onAccept: (int data) {
|
}),
|
||||||
events.add('drop');
|
]);
|
||||||
}
|
},
|
||||||
),
|
}));
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -331,44 +290,33 @@ void main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Drag and drop - horizontal and vertical draggables in vertical block', () {
|
test('Drag and drop - horizontal and vertical draggables in vertical block',
|
||||||
|
() {
|
||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation, thirdLocation;
|
Point firstLocation, secondLocation, thirdLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) {
|
return new Block(children: <Widget>[
|
||||||
return new Block(
|
new DragTarget<int>(builder:
|
||||||
children: <Widget>[
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
new DragTarget<int>(
|
return new Text('Target');
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
}, onAccept: (int data) {
|
||||||
return new Text('Target');
|
events.add('drop $data');
|
||||||
},
|
}),
|
||||||
onAccept: (int data) {
|
new Container(height: 400.0),
|
||||||
events.add('drop $data');
|
new HorizontalDraggable<int>(
|
||||||
}
|
data: 1, child: new Text('H'), feedback: new Text('Dragging')),
|
||||||
),
|
new VerticalDraggable<int>(
|
||||||
new Container(height: 400.0),
|
data: 2, child: new Text('V'), feedback: new Text('Dragging')),
|
||||||
new HorizontalDraggable<int>(
|
new Container(height: 500.0),
|
||||||
data: 1,
|
new Container(height: 500.0),
|
||||||
child: new Text('H'),
|
new Container(height: 500.0),
|
||||||
feedback: new Text('Dragging')
|
new Container(height: 500.0),
|
||||||
),
|
]);
|
||||||
new VerticalDraggable<int>(
|
},
|
||||||
data: 2,
|
}));
|
||||||
child: new Text('V'),
|
|
||||||
feedback: new Text('Dragging')
|
|
||||||
),
|
|
||||||
new Container(height: 500.0),
|
|
||||||
new Container(height: 500.0),
|
|
||||||
new Container(height: 500.0),
|
|
||||||
new Container(height: 500.0),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Target'), isNotNull);
|
expect(tester.findText('Target'), isNotNull);
|
||||||
@ -438,49 +386,36 @@ void main() {
|
|||||||
expect(events, equals(<String>[]));
|
expect(events, equals(<String>[]));
|
||||||
expect(tester.getCenter(tester.findText('Target')).y, lessThan(0.0));
|
expect(tester.getCenter(tester.findText('Target')).y, lessThan(0.0));
|
||||||
events.clear();
|
events.clear();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Drag and drop - horizontal and vertical draggables in horizontal block', () {
|
test('Drag and drop - horizontal and vertical draggables in horizontal block',
|
||||||
|
() {
|
||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<String> events = <String>[];
|
List<String> events = <String>[];
|
||||||
Point firstLocation, secondLocation, thirdLocation;
|
Point firstLocation, secondLocation, thirdLocation;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) {
|
return new Block(scrollDirection: Axis.horizontal, children: <Widget>[
|
||||||
return new Block(
|
new DragTarget<int>(builder:
|
||||||
scrollDirection: Axis.horizontal,
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
children: <Widget>[
|
return new Text('Target');
|
||||||
new DragTarget<int>(
|
}, onAccept: (int data) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
events.add('drop $data');
|
||||||
return new Text('Target');
|
}),
|
||||||
},
|
new Container(width: 400.0),
|
||||||
onAccept: (int data) {
|
new HorizontalDraggable<int>(
|
||||||
events.add('drop $data');
|
data: 1, child: new Text('H'), feedback: new Text('Dragging')),
|
||||||
}
|
new VerticalDraggable<int>(
|
||||||
),
|
data: 2, child: new Text('V'), feedback: new Text('Dragging')),
|
||||||
new Container(width: 400.0),
|
new Container(width: 500.0),
|
||||||
new HorizontalDraggable<int>(
|
new Container(width: 500.0),
|
||||||
data: 1,
|
new Container(width: 500.0),
|
||||||
child: new Text('H'),
|
new Container(width: 500.0),
|
||||||
feedback: new Text('Dragging')
|
]);
|
||||||
),
|
},
|
||||||
new VerticalDraggable<int>(
|
}));
|
||||||
data: 2,
|
|
||||||
child: new Text('V'),
|
|
||||||
feedback: new Text('Dragging')
|
|
||||||
),
|
|
||||||
new Container(width: 500.0),
|
|
||||||
new Container(width: 500.0),
|
|
||||||
new Container(width: 500.0),
|
|
||||||
new Container(width: 500.0),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(events, isEmpty);
|
expect(events, isEmpty);
|
||||||
expect(tester.findText('Target'), isNotNull);
|
expect(tester.findText('Target'), isNotNull);
|
||||||
@ -550,42 +485,35 @@ void main() {
|
|||||||
expect(events, equals(<String>[]));
|
expect(events, equals(<String>[]));
|
||||||
expect(tester.getCenter(tester.findText('Target')).x, lessThan(0.0));
|
expect(tester.getCenter(tester.findText('Target')).x, lessThan(0.0));
|
||||||
events.clear();
|
events.clear();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Drag and drop - onDraggableDropped not called if dropped on accepting target', () {
|
test(
|
||||||
|
'Drag and drop - onDraggableDropped not called if dropped on accepting target',
|
||||||
|
() {
|
||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<int> accepted = <int>[];
|
List<int> accepted = <int>[];
|
||||||
bool onDraggableCanceledCalled = false;
|
bool onDraggableCanceledCalled = false;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging'),
|
feedback: new Text('Dragging'),
|
||||||
onDraggableCanceled: (Velocity velocity, Offset offset) {
|
onDraggableCanceled: (Velocity velocity, Offset offset) {
|
||||||
onDraggableCanceledCalled = true;
|
onDraggableCanceledCalled = true;
|
||||||
}
|
}),
|
||||||
),
|
new DragTarget<int>(builder:
|
||||||
new DragTarget<int>(
|
(BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
return new Container(height: 100.0, child: new Text('Target'));
|
||||||
return new Container(
|
}, onAccept: (int data) {
|
||||||
height: 100.0,
|
accepted.add(data);
|
||||||
child: new Text('Target')
|
}),
|
||||||
);
|
]);
|
||||||
},
|
},
|
||||||
onAccept: (int data) {
|
}));
|
||||||
accepted.add(data);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(accepted, isEmpty);
|
expect(accepted, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -624,18 +552,19 @@ void main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Drag and drop - onDraggableDropped called if dropped on non-accepting target', () {
|
test(
|
||||||
|
'Drag and drop - onDraggableDropped called if dropped on non-accepting target',
|
||||||
|
() {
|
||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<int> accepted = <int>[];
|
List<int> accepted = <int>[];
|
||||||
bool onDraggableCanceledCalled = false;
|
bool onDraggableCanceledCalled = false;
|
||||||
Velocity onDraggableCanceledVelocity;
|
Velocity onDraggableCanceledVelocity;
|
||||||
Offset onDraggableCanceledOffset;
|
Offset onDraggableCanceledOffset;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Dragging'),
|
feedback: new Text('Dragging'),
|
||||||
@ -643,21 +572,17 @@ void main() {
|
|||||||
onDraggableCanceledCalled = true;
|
onDraggableCanceledCalled = true;
|
||||||
onDraggableCanceledVelocity = velocity;
|
onDraggableCanceledVelocity = velocity;
|
||||||
onDraggableCanceledOffset = offset;
|
onDraggableCanceledOffset = offset;
|
||||||
}
|
}),
|
||||||
),
|
new DragTarget<int>(
|
||||||
new DragTarget<int>(
|
builder: (BuildContext context, List<int> data,
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
List<dynamic> rejects) {
|
||||||
return new Container(
|
return new Container(
|
||||||
height: 100.0,
|
height: 100.0, child: new Text('Target'));
|
||||||
child: new Text('Target')
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onWillAccept: (int data) => false
|
onWillAccept: (int data) => false),
|
||||||
),
|
]);
|
||||||
]);
|
},
|
||||||
},
|
}));
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(accepted, isEmpty);
|
expect(accepted, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -694,22 +619,24 @@ void main() {
|
|||||||
expect(tester.findText('Target'), isNotNull);
|
expect(tester.findText('Target'), isNotNull);
|
||||||
expect(onDraggableCanceledCalled, isTrue);
|
expect(onDraggableCanceledCalled, isTrue);
|
||||||
expect(onDraggableCanceledVelocity, equals(Velocity.zero));
|
expect(onDraggableCanceledVelocity, equals(Velocity.zero));
|
||||||
expect(onDraggableCanceledOffset, equals(new Offset(secondLocation.x, secondLocation.y)));
|
expect(onDraggableCanceledOffset,
|
||||||
|
equals(new Offset(secondLocation.x, secondLocation.y)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Drag and drop - onDraggableDropped called if dropped on non-accepting target with correct velocity', () {
|
test(
|
||||||
|
'Drag and drop - onDraggableDropped called if dropped on non-accepting target with correct velocity',
|
||||||
|
() {
|
||||||
testWidgets((WidgetTester tester) {
|
testWidgets((WidgetTester tester) {
|
||||||
List<int> accepted = <int>[];
|
List<int> accepted = <int>[];
|
||||||
bool onDraggableCanceledCalled = false;
|
bool onDraggableCanceledCalled = false;
|
||||||
Velocity onDraggableCanceledVelocity;
|
Velocity onDraggableCanceledVelocity;
|
||||||
Offset onDraggableCanceledOffset;
|
Offset onDraggableCanceledOffset;
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('Source'),
|
child: new Text('Source'),
|
||||||
feedback: new Text('Source'),
|
feedback: new Text('Source'),
|
||||||
@ -717,21 +644,17 @@ void main() {
|
|||||||
onDraggableCanceledCalled = true;
|
onDraggableCanceledCalled = true;
|
||||||
onDraggableCanceledVelocity = velocity;
|
onDraggableCanceledVelocity = velocity;
|
||||||
onDraggableCanceledOffset = offset;
|
onDraggableCanceledOffset = offset;
|
||||||
}
|
}),
|
||||||
),
|
new DragTarget<int>(
|
||||||
new DragTarget<int>(
|
builder: (BuildContext context, List<int> data,
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
List<dynamic> rejects) {
|
||||||
return new Container(
|
return new Container(
|
||||||
height: 100.0,
|
height: 100.0, child: new Text('Target'));
|
||||||
child: new Text('Target')
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onWillAccept: (int data) => false
|
onWillAccept: (int data) => false),
|
||||||
),
|
]);
|
||||||
]);
|
},
|
||||||
},
|
}));
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(accepted, isEmpty);
|
expect(accepted, isEmpty);
|
||||||
expect(tester.findText('Source'), isNotNull);
|
expect(tester.findText('Source'), isNotNull);
|
||||||
@ -740,7 +663,7 @@ void main() {
|
|||||||
expect(onDraggableCanceledCalled, isFalse);
|
expect(onDraggableCanceledCalled, isFalse);
|
||||||
|
|
||||||
Point flingStart = tester.getTopLeft(tester.findText('Source'));
|
Point flingStart = tester.getTopLeft(tester.findText('Source'));
|
||||||
tester.flingFrom(flingStart, new Offset(0.0,100.0), 1000.0);
|
tester.flingFrom(flingStart, new Offset(0.0, 100.0), 1000.0);
|
||||||
tester.pump();
|
tester.pump();
|
||||||
|
|
||||||
expect(accepted, isEmpty);
|
expect(accepted, isEmpty);
|
||||||
@ -748,9 +671,14 @@ void main() {
|
|||||||
expect(tester.findText('Dragging'), isNull);
|
expect(tester.findText('Dragging'), isNull);
|
||||||
expect(tester.findText('Target'), isNotNull);
|
expect(tester.findText('Target'), isNotNull);
|
||||||
expect(onDraggableCanceledCalled, isTrue);
|
expect(onDraggableCanceledCalled, isTrue);
|
||||||
expect(onDraggableCanceledVelocity.pixelsPerSecond.dx.abs(), lessThan(0.0000001));
|
expect(onDraggableCanceledVelocity.pixelsPerSecond.dx.abs(),
|
||||||
expect((onDraggableCanceledVelocity.pixelsPerSecond.dy - 1000.0).abs(), lessThan(0.0000001));
|
lessThan(0.0000001));
|
||||||
expect(onDraggableCanceledOffset, equals(new Offset(flingStart.x, flingStart.y) + new Offset(0.0, 100.0)));
|
expect((onDraggableCanceledVelocity.pixelsPerSecond.dy - 1000.0).abs(),
|
||||||
|
lessThan(0.0000001));
|
||||||
|
expect(
|
||||||
|
onDraggableCanceledOffset,
|
||||||
|
equals(
|
||||||
|
new Offset(flingStart.x, flingStart.y) + new Offset(0.0, 100.0)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -759,52 +687,36 @@ void main() {
|
|||||||
List<int> acceptedInts = <int>[];
|
List<int> acceptedInts = <int>[];
|
||||||
List<double> acceptedDoubles = <double>[];
|
List<double> acceptedDoubles = <double>[];
|
||||||
|
|
||||||
tester.pumpWidget(new MaterialApp(
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
routes: <String, WidgetBuilder>{
|
'/': (BuildContext context) {
|
||||||
'/': (BuildContext context) { return new Column(
|
return new Column(children: <Widget>[
|
||||||
children: <Widget>[
|
new Draggable<int>(
|
||||||
new Draggable<int>(
|
|
||||||
data: 1,
|
data: 1,
|
||||||
child: new Text('IntSource'),
|
child: new Text('IntSource'),
|
||||||
feedback: new Text('IntDragging')
|
feedback: new Text('IntDragging')),
|
||||||
),
|
new Draggable<double>(
|
||||||
new Draggable<double>(
|
|
||||||
data: 1.0,
|
data: 1.0,
|
||||||
child: new Text('DoubleSource'),
|
child: new Text('DoubleSource'),
|
||||||
feedback: new Text('DoubleDragging')
|
feedback: new Text('DoubleDragging')),
|
||||||
),
|
new Stack(children: [
|
||||||
new Stack(children:[
|
new DragTarget<int>(builder: (BuildContext context,
|
||||||
new DragTarget<int>(
|
List<int> data, List<dynamic> rejects) {
|
||||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
return new IgnorePointer(child: new Container(
|
||||||
return new IgnorePointer(
|
height: 100.0, child: new Text('Target1')));
|
||||||
child: new Container(
|
}, onAccept: (int data) {
|
||||||
height: 100.0,
|
acceptedInts.add(data);
|
||||||
child: new Text('Target1')
|
}),
|
||||||
)
|
new DragTarget<double>(builder: (BuildContext context,
|
||||||
);
|
List<double> data, List<dynamic> rejects) {
|
||||||
},
|
return new IgnorePointer(child: new Container(
|
||||||
onAccept: (int data) {
|
height: 100.0, child: new Text('Target2')));
|
||||||
acceptedInts.add(data);
|
}, onAccept: (double data) {
|
||||||
}
|
acceptedDoubles.add(data);
|
||||||
),
|
}),
|
||||||
new DragTarget<double>(
|
])
|
||||||
builder: (BuildContext context, List<double> data, List<dynamic> rejects) {
|
]);
|
||||||
return new IgnorePointer(
|
},
|
||||||
child: new Container(
|
}));
|
||||||
height: 100.0,
|
|
||||||
child: new Text('Target2')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onAccept: (double data) {
|
|
||||||
acceptedDoubles.add(data);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
])
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
expect(acceptedInts, isEmpty);
|
expect(acceptedInts, isEmpty);
|
||||||
expect(acceptedDoubles, isEmpty);
|
expect(acceptedDoubles, isEmpty);
|
||||||
@ -820,7 +732,8 @@ void main() {
|
|||||||
Point targetLocation = tester.getCenter(tester.findText('Target1'));
|
Point targetLocation = tester.getCenter(tester.findText('Target1'));
|
||||||
|
|
||||||
// Drag the double draggable.
|
// Drag the double draggable.
|
||||||
TestGesture doubleGesture = tester.startGesture(doubleLocation, pointer: 7);
|
TestGesture doubleGesture =
|
||||||
|
tester.startGesture(doubleLocation, pointer: 7);
|
||||||
tester.pump();
|
tester.pump();
|
||||||
|
|
||||||
expect(acceptedInts, isEmpty);
|
expect(acceptedInts, isEmpty);
|
||||||
@ -872,4 +785,62 @@ void main() {
|
|||||||
expect(tester.findText('DoubleDragging'), isNull);
|
expect(tester.findText('DoubleDragging'), isNull);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Drag and drop - allow pass thru of unaccepted data twice test', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
List<DragTargetData> acceptedDragTargetDatas = <DragTargetData>[];
|
||||||
|
List<ExtendedDragTargetData> acceptedExtendedDragTargetDatas = <ExtendedDragTargetData>[];
|
||||||
|
DragTargetData dragTargetData = new DragTargetData();
|
||||||
|
tester.pumpWidget(new MaterialApp(routes: <String, WidgetBuilder>{
|
||||||
|
'/': (BuildContext context) {
|
||||||
|
return new Column(children: <Widget>[
|
||||||
|
new Draggable<DragTargetData>(
|
||||||
|
data: dragTargetData,
|
||||||
|
child: new Text('Source'),
|
||||||
|
feedback: new Text('Dragging')),
|
||||||
|
new Stack(children: [
|
||||||
|
new DragTarget<DragTargetData>(builder: (BuildContext context,
|
||||||
|
List<DragTargetData> data, List<dynamic> rejects) {
|
||||||
|
return new IgnorePointer(child: new Container(
|
||||||
|
height: 100.0, child: new Text('Target1')));
|
||||||
|
}, onAccept: (DragTargetData data) {
|
||||||
|
acceptedDragTargetDatas.add(data);
|
||||||
|
}),
|
||||||
|
new DragTarget<ExtendedDragTargetData>(builder: (BuildContext context,
|
||||||
|
List<ExtendedDragTargetData> data, List<ExtendedDragTargetData> rejects) {
|
||||||
|
return new IgnorePointer(child: new Container(
|
||||||
|
height: 100.0, child: new Text('Target2')));
|
||||||
|
}, onAccept: (ExtendedDragTargetData data) {
|
||||||
|
acceptedExtendedDragTargetDatas.add(data);
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
Point dragTargetLocation = tester.getCenter(tester.findText('Source'));
|
||||||
|
Point targetLocation = tester.getCenter(tester.findText('Target1'));
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i += 1) {
|
||||||
|
TestGesture gesture = tester.startGesture(dragTargetLocation);
|
||||||
|
tester.pump();
|
||||||
|
gesture.moveTo(targetLocation);
|
||||||
|
tester.pump();
|
||||||
|
gesture.up();
|
||||||
|
tester.pump();
|
||||||
|
|
||||||
|
expect(acceptedDragTargetDatas, equals(<DragTargetData>[dragTargetData]));
|
||||||
|
expect(acceptedExtendedDragTargetDatas, isEmpty);
|
||||||
|
|
||||||
|
acceptedDragTargetDatas.clear();
|
||||||
|
tester.pump();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class DragTargetData {
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExtendedDragTargetData extends DragTargetData {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user