Skip to content

Commit 75d8fb3

Browse files
authored
Remove deprecated drag anchor (#111713)
1 parent 55ad0ab commit 75d8fb3

File tree

2 files changed

+7
-76
lines changed

2 files changed

+7
-76
lines changed

packages/flutter/lib/src/widgets/drag_target.dart

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef DragAnchorStrategy = Offset Function(Draggable<Object> draggable, BuildC
8686
/// If feedback is identical to the child, then this means the feedback will
8787
/// exactly overlap the original child when the drag starts.
8888
///
89-
/// This is the default [DragAnchorStrategy] and replaces [DragAnchor.child].
89+
/// This is the default [DragAnchorStrategy].
9090
///
9191
/// See also:
9292
///
@@ -110,8 +110,6 @@ Offset childDragAnchorStrategy(Draggable<Object> draggable, BuildContext context
110110
/// weird for it to appear offset from the original child if it's anchored to
111111
/// the child and not the finger.)
112112
///
113-
/// This replaces [DragAnchor.pointer], which has been deprecated.
114-
///
115113
/// See also:
116114
///
117115
/// * [DragAnchorStrategy], the typedef that this function implements.
@@ -120,34 +118,6 @@ Offset pointerDragAnchorStrategy(Draggable<Object> draggable, BuildContext conte
120118
return Offset.zero;
121119
}
122120

123-
/// Where the [Draggable] should be anchored during a drag.
124-
///
125-
/// This has been replaced by the more configurable [DragAnchorStrategy].
126-
@Deprecated(
127-
'Use dragAnchorStrategy instead. '
128-
'This feature was deprecated after v2.1.0-10.0.pre.',
129-
)
130-
enum DragAnchor {
131-
/// Display the feedback anchored at the position of the original child.
132-
///
133-
/// Replaced by [childDragAnchorStrategy].
134-
@Deprecated(
135-
'Use childDragAnchorStrategy instead. '
136-
'This feature was deprecated after v2.1.0-10.0.pre.',
137-
)
138-
child,
139-
140-
/// Display the feedback anchored at the position of the touch that started
141-
/// the drag.
142-
///
143-
/// Replaced by [pointerDragAnchorStrategy].
144-
@Deprecated(
145-
'Use pointerDragAnchorStrategy instead. '
146-
'This feature was deprecated after v2.1.0-10.0.pre.',
147-
)
148-
pointer,
149-
}
150-
151121
/// A widget that can be dragged from to a [DragTarget].
152122
///
153123
/// When a draggable widget recognizes the start of a drag gesture, it displays
@@ -197,14 +167,7 @@ class Draggable<T extends Object> extends StatefulWidget {
197167
this.axis,
198168
this.childWhenDragging,
199169
this.feedbackOffset = Offset.zero,
200-
@Deprecated(
201-
'Use dragAnchorStrategy instead. '
202-
'Replace "dragAnchor: DragAnchor.child" with "dragAnchorStrategy: childDragAnchorStrategy". '
203-
'Replace "dragAnchor: DragAnchor.pointer" with "dragAnchorStrategy: pointerDragAnchorStrategy". '
204-
'This feature was deprecated after v2.1.0-10.0.pre.',
205-
)
206-
this.dragAnchor = DragAnchor.child,
207-
this.dragAnchorStrategy,
170+
this.dragAnchorStrategy = childDragAnchorStrategy,
208171
this.affinity,
209172
this.maxSimultaneousDrags,
210173
this.onDragStarted,
@@ -220,7 +183,8 @@ class Draggable<T extends Object> extends StatefulWidget {
220183
assert(feedback != null),
221184
assert(ignoringFeedbackSemantics != null),
222185
assert(ignoringFeedbackPointer != null),
223-
assert(maxSimultaneousDrags == null || maxSimultaneousDrags >= 0);
186+
assert(maxSimultaneousDrags == null || maxSimultaneousDrags >= 0),
187+
assert(dragAnchorStrategy != null);
224188

225189
/// The data that will be dropped by this draggable.
226190
final T? data;
@@ -276,17 +240,6 @@ class Draggable<T extends Object> extends StatefulWidget {
276240
/// is transformed compared to the child.
277241
final Offset feedbackOffset;
278242

279-
/// Where this widget should be anchored during a drag.
280-
///
281-
/// This property is overridden by the [dragAnchorStrategy] if the latter is provided.
282-
///
283-
/// Defaults to [DragAnchor.child].
284-
@Deprecated(
285-
'Use dragAnchorStrategy instead. '
286-
'This feature was deprecated after v2.1.0-10.0.pre.',
287-
)
288-
final DragAnchor dragAnchor;
289-
290243
/// A strategy that is used by this draggable to get the anchor offset when it
291244
/// is dragged.
292245
///
@@ -302,10 +255,8 @@ class Draggable<T extends Object> extends StatefulWidget {
302255
/// * [pointerDragAnchorStrategy], which displays the feedback anchored at the
303256
/// position of the touch that started the drag.
304257
///
305-
/// Defaults to [childDragAnchorStrategy] if the deprecated [dragAnchor]
306-
/// property is set to [DragAnchor.child], and [pointerDragAnchorStrategy] if
307-
/// the [dragAnchor] is set to [DragAnchor.pointer].
308-
final DragAnchorStrategy? dragAnchorStrategy;
258+
/// Defaults to [childDragAnchorStrategy].
259+
final DragAnchorStrategy dragAnchorStrategy;
309260

310261
/// Whether the semantics of the [feedback] widget is ignored when building
311262
/// the semantics tree.
@@ -447,13 +398,6 @@ class LongPressDraggable<T extends Object> extends Draggable<T> {
447398
super.axis,
448399
super.childWhenDragging,
449400
super.feedbackOffset,
450-
@Deprecated(
451-
'Use dragAnchorStrategy instead. '
452-
'Replace "dragAnchor: DragAnchor.child" with "dragAnchorStrategy: childDragAnchorStrategy". '
453-
'Replace "dragAnchor: DragAnchor.pointer" with "dragAnchorStrategy: pointerDragAnchorStrategy". '
454-
'This feature was deprecated after v2.1.0-10.0.pre.',
455-
)
456-
super.dragAnchor,
457401
super.dragAnchorStrategy,
458402
super.maxSimultaneousDrags,
459403
super.onDragStarted,
@@ -539,18 +483,7 @@ class _DraggableState<T extends Object> extends State<Draggable<T>> {
539483
return null;
540484
}
541485
final Offset dragStartPoint;
542-
if (widget.dragAnchorStrategy == null) {
543-
switch (widget.dragAnchor) {
544-
case DragAnchor.child:
545-
dragStartPoint = childDragAnchorStrategy(widget, context, position);
546-
break;
547-
case DragAnchor.pointer:
548-
dragStartPoint = pointerDragAnchorStrategy(widget, context, position);
549-
break;
550-
}
551-
} else {
552-
dragStartPoint = widget.dragAnchorStrategy!(widget, context, position);
553-
}
486+
dragStartPoint = widget.dragAnchorStrategy(widget, context, position);
554487
setState(() {
555488
_activeCount += 1;
556489
});

packages/flutter/test/widgets/draggable_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,8 +3192,6 @@ void main() {
31923192
expect(const LongPressDraggable<int>(feedback: widget2, child: widget1), isA<Draggable<int>>());
31933193
expect(const LongPressDraggable<int>(feedback: widget2, child: widget1).child, widget1);
31943194
expect(const LongPressDraggable<int>(feedback: widget2, child: widget1).feedback, widget2);
3195-
expect(const LongPressDraggable<int>(feedback: widget2, child: widget1).dragAnchor, DragAnchor.child);
3196-
expect(const LongPressDraggable<int>(feedback: widget2, dragAnchor: DragAnchor.pointer, child: widget1).dragAnchor, DragAnchor.pointer);
31973195
expect(LongPressDraggable<int>(feedback: widget2, dragAnchorStrategy: dummyStrategy, child: widget1).dragAnchorStrategy, dummyStrategy);
31983196
});
31993197
}

0 commit comments

Comments
 (0)