feat: Add velocity to DragTargetDetails This commit adds a velocity parameter to the DragTargetDetails class, and where this class is used, supplies the velocity to this new parameter. Fixes https://github.com/flutter/flutter/issues/165878
diff --git a/packages/flutter/lib/src/widgets/drag_target.dart b/packages/flutter/lib/src/widgets/drag_target.dart index bcabe27..5f087bd 100644 --- a/packages/flutter/lib/src/widgets/drag_target.dart +++ b/packages/flutter/lib/src/widgets/drag_target.dart
@@ -886,7 +886,7 @@ void update(DragUpdateDetails details) { final Offset oldPosition = _position; _position += _restrictAxis(details.delta); - velocity = Velocity(pixelsPerSecond: _position); + velocity = Velocity(pixelsPerSecond: _position - oldPosition); updateDrag(_position); if (onDragUpdate != null && _position != oldPosition) { onDragUpdate!(details);
diff --git a/packages/flutter/test/widgets/draggable_test.dart b/packages/flutter/test/widgets/draggable_test.dart index da01bc1..1b605d9 100644 --- a/packages/flutter/test/widgets/draggable_test.dart +++ b/packages/flutter/test/widgets/draggable_test.dart
@@ -87,7 +87,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -1254,7 +1254,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -1992,7 +1992,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2137,7 +2137,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2233,7 +2233,7 @@ expect(acceptedDoubles, equals(<double>[1.0])); expect(acceptedDoublesDetails, hasLength(1)); expect(acceptedDoublesDetails.first.offset, const Offset(112.0, 122.0)); - expect(acceptedDoublesDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDoublesDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('IntDragging'), findsNothing); expect(find.text('DoubleDragging'), findsNothing); @@ -2267,7 +2267,7 @@ expect(acceptedInts, equals(<int>[1])); expect(acceptedIntsDetails, hasLength(1)); expect(acceptedIntsDetails.first.offset, const Offset(184.0, 122.0)); - expect(acceptedIntsDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedIntsDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(acceptedDoubles, isEmpty); expect(acceptedDoublesDetails, isEmpty); expect(find.text('IntDragging'), findsNothing); @@ -2340,7 +2340,7 @@ expect(acceptedDragTargetDatas, equals(<DragTargetData>[dragTargetData])); expect(acceptedDragTargetDataDetails, hasLength(1)); expect(acceptedDragTargetDataDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDragTargetDataDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDragTargetDataDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(acceptedExtendedDragTargetDatas, isEmpty); expect(acceptedExtendedDragTargetDataDetails, isEmpty); @@ -2450,7 +2450,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsOneWidget); expect(find.text('Target'), findsOneWidget); @@ -2461,9 +2461,9 @@ expect(accepted, equals(<int>[1, 1])); expect(acceptedDetails, hasLength(2)); expect(acceptedDetails[0].offset, const Offset(256.0, 74.0)); - expect(acceptedDetails[0].velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails[0].velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(acceptedDetails[1].offset, const Offset(256.0, 74.0)); - expect(acceptedDetails[1].velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails[1].velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2474,9 +2474,9 @@ expect(accepted, equals(<int>[1, 1])); expect(acceptedDetails, hasLength(2)); expect(acceptedDetails[0].offset, const Offset(256.0, 74.0)); - expect(acceptedDetails[0].velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails[0].velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(acceptedDetails[1].offset, const Offset(256.0, 74.0)); - expect(acceptedDetails[1].velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails[1].velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2771,7 +2771,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, const Offset(256.0, 26.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsNothing); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2883,7 +2883,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails, hasLength(1)); expect(acceptedDetails.first.offset, expectedDropOffset); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(256.0, 74.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget); @@ -2968,7 +2968,7 @@ expect(accepted, equals(<int>[1])); expect(acceptedDetails.first.offset, const Offset(256.0, 74.0)); - expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(400.0, 150.0))); + expect(acceptedDetails.first.velocity, const Velocity(pixelsPerSecond: Offset(0.0, 52.0))); expect(find.text('Source'), findsOneWidget); expect(find.text('Dragging'), findsNothing); expect(find.text('Target'), findsOneWidget);