Unverified Commit 347f7bac authored by Chinmoy's avatar Chinmoy Committed by GitHub

Adds callback onWillAcceptWithDetails in DragTarget. (#131545)

This PR adds onWillAcceptWithDetails callback to DragTarget to get information about offset.

Fixes: #131378 

This PR is subject to changes based on #131542
parent 72bd3602
...@@ -20,6 +20,12 @@ import 'view.dart'; ...@@ -20,6 +20,12 @@ import 'view.dart';
/// Used by [DragTarget.onWillAccept]. /// Used by [DragTarget.onWillAccept].
typedef DragTargetWillAccept<T> = bool Function(T? data); typedef DragTargetWillAccept<T> = bool Function(T? data);
/// Signature for determining whether the given data will be accepted by a [DragTarget],
/// based on provided information.
///
/// Used by [DragTarget.onWillAcceptWithDetails].
typedef DragTargetWillAcceptWithDetails<T> = bool Function(DragTargetDetails<T> details);
/// Signature for causing a [DragTarget] to accept the given data. /// Signature for causing a [DragTarget] to accept the given data.
/// ///
/// Used by [DragTarget.onAccept]. /// Used by [DragTarget.onAccept].
...@@ -612,12 +618,13 @@ class DragTarget<T extends Object> extends StatefulWidget { ...@@ -612,12 +618,13 @@ class DragTarget<T extends Object> extends StatefulWidget {
super.key, super.key,
required this.builder, required this.builder,
this.onWillAccept, this.onWillAccept,
this.onWillAcceptWithDetails,
this.onAccept, this.onAccept,
this.onAcceptWithDetails, this.onAcceptWithDetails,
this.onLeave, this.onLeave,
this.onMove, this.onMove,
this.hitTestBehavior = HitTestBehavior.translucent, this.hitTestBehavior = HitTestBehavior.translucent,
}); }) : assert(onWillAccept == null || onWillAcceptWithDetails == null, "Don't pass both onWillAccept and onWillAcceptWithDetails.");
/// Called to build the contents of this widget. /// Called to build the contents of this widget.
/// ///
...@@ -631,8 +638,25 @@ class DragTarget<T extends Object> extends StatefulWidget { ...@@ -631,8 +638,25 @@ class DragTarget<T extends Object> extends StatefulWidget {
/// Called when a piece of data enters the target. This will be followed by /// Called when a piece of data enters the target. This will be followed by
/// either [onAccept] and [onAcceptWithDetails], if the data is dropped, or /// either [onAccept] and [onAcceptWithDetails], if the data is dropped, or
/// [onLeave], if the drag leaves the target. /// [onLeave], if the drag leaves the target.
///
/// Equivalent to [onWillAcceptWithDetails], but only includes the data.
///
/// Must not be provided if [onWillAcceptWithDetails] is provided.
final DragTargetWillAccept<T>? onWillAccept; final DragTargetWillAccept<T>? onWillAccept;
/// Called to determine whether this widget is interested in receiving a given
/// piece of data being dragged over this drag target.
///
/// Called when a piece of data enters the target. This will be followed by
/// either [onAccept] and [onAcceptWithDetails], if the data is dropped, or
/// [onLeave], if the drag leaves the target.
///
/// Equivalent to [onWillAccept], but with information, including the data,
/// in a [DragTargetDetails].
///
/// Must not be provided if [onWillAccept] is provided.
final DragTargetWillAcceptWithDetails<T>? onWillAcceptWithDetails;
/// Called when an acceptable piece of data was dropped over this drag target. /// Called when an acceptable piece of data was dropped over this drag target.
/// ///
/// Equivalent to [onAcceptWithDetails], but only includes the data. /// Equivalent to [onAcceptWithDetails], but only includes the data.
...@@ -684,7 +708,13 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> { ...@@ -684,7 +708,13 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
bool didEnter(_DragAvatar<Object> avatar) { bool didEnter(_DragAvatar<Object> avatar) {
assert(!_candidateAvatars.contains(avatar)); assert(!_candidateAvatars.contains(avatar));
assert(!_rejectedAvatars.contains(avatar)); assert(!_rejectedAvatars.contains(avatar));
if (widget.onWillAccept == null || widget.onWillAccept!(avatar.data as T?)) { final bool resolvedWillAccept = (widget.onWillAccept == null &&
widget.onWillAcceptWithDetails == null) ||
(widget.onWillAccept != null &&
widget.onWillAccept!(avatar.data as T?)) ||
(widget.onWillAcceptWithDetails != null &&
widget.onWillAcceptWithDetails!(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!)));
if (resolvedWillAccept) {
setState(() { setState(() {
_candidateAvatars.add(avatar); _candidateAvatars.add(avatar);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment