@@ -75,6 +75,7 @@ class Draggable<T> extends StatefulWidget {
|
||||
this.dragAnchor: DragAnchor.child,
|
||||
this.affinity,
|
||||
this.maxSimultaneousDrags,
|
||||
this.onDragStarted,
|
||||
this.onDraggableCanceled
|
||||
}) : super(key: key) {
|
||||
assert(child != null);
|
||||
@@ -127,6 +128,9 @@ class Draggable<T> extends StatefulWidget {
|
||||
/// dragged at a time.
|
||||
final int maxSimultaneousDrags;
|
||||
|
||||
/// Called when the draggable starts being dragged.
|
||||
final VoidCallback onDragStarted;
|
||||
|
||||
/// Called when the draggable is dropped without being accepted by a [DragTarget].
|
||||
final DraggableCanceledCallback onDraggableCanceled;
|
||||
|
||||
@@ -164,6 +168,7 @@ class LongPressDraggable<T> extends Draggable<T> {
|
||||
Offset feedbackOffset: Offset.zero,
|
||||
DragAnchor dragAnchor: DragAnchor.child,
|
||||
int maxSimultaneousDrags,
|
||||
VoidCallback onDragStarted,
|
||||
DraggableCanceledCallback onDraggableCanceled
|
||||
}) : super(
|
||||
key: key,
|
||||
@@ -174,6 +179,7 @@ class LongPressDraggable<T> extends Draggable<T> {
|
||||
feedbackOffset: feedbackOffset,
|
||||
dragAnchor: dragAnchor,
|
||||
maxSimultaneousDrags: maxSimultaneousDrags,
|
||||
onDragStarted: onDragStarted,
|
||||
onDraggableCanceled: onDraggableCanceled
|
||||
);
|
||||
|
||||
@@ -227,7 +233,7 @@ class _DraggableState<T> extends State<Draggable<T>> {
|
||||
setState(() {
|
||||
_activeCount += 1;
|
||||
});
|
||||
return new _DragAvatar<T>(
|
||||
final _DragAvatar<T> avatar = new _DragAvatar<T>(
|
||||
overlay: Overlay.of(context, debugRequiredFor: config),
|
||||
data: config.data,
|
||||
initialPosition: position,
|
||||
@@ -242,6 +248,9 @@ class _DraggableState<T> extends State<Draggable<T>> {
|
||||
});
|
||||
}
|
||||
);
|
||||
if (config.onDragStarted != null)
|
||||
config.onDragStarted();
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||
void main() {
|
||||
testWidgets('Drag and drop - control test', (WidgetTester tester) async {
|
||||
List<int> accepted = <int>[];
|
||||
int dragStartedCount = 0;
|
||||
|
||||
await tester.pumpWidget(new MaterialApp(
|
||||
home: new Column(
|
||||
@@ -15,7 +16,10 @@ void main() {
|
||||
new Draggable<int>(
|
||||
data: 1,
|
||||
child: new Text('Source'),
|
||||
feedback: new Text('Dragging')
|
||||
feedback: new Text('Dragging'),
|
||||
onDragStarted: () {
|
||||
++dragStartedCount;
|
||||
},
|
||||
),
|
||||
new DragTarget<int>(
|
||||
builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
|
||||
@@ -33,6 +37,7 @@ void main() {
|
||||
expect(find.text('Source'), findsOneWidget);
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(dragStartedCount, 0);
|
||||
|
||||
Point firstLocation = tester.getCenter(find.text('Source'));
|
||||
TestGesture gesture = await tester.startGesture(firstLocation, pointer: 7);
|
||||
@@ -42,6 +47,7 @@ void main() {
|
||||
expect(find.text('Source'), findsOneWidget);
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(dragStartedCount, 1);
|
||||
|
||||
Point secondLocation = tester.getCenter(find.text('Target'));
|
||||
await gesture.moveTo(secondLocation);
|
||||
@@ -51,6 +57,7 @@ void main() {
|
||||
expect(find.text('Source'), findsOneWidget);
|
||||
expect(find.text('Dragging'), findsOneWidget);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(dragStartedCount, 1);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
@@ -59,6 +66,7 @@ void main() {
|
||||
expect(find.text('Source'), findsOneWidget);
|
||||
expect(find.text('Dragging'), findsNothing);
|
||||
expect(find.text('Target'), findsOneWidget);
|
||||
expect(dragStartedCount, 1);
|
||||
});
|
||||
|
||||
testWidgets('Drag and drop - dragging over button', (WidgetTester tester) async {
|
||||
|
||||
Reference in New Issue
Block a user