Unverified Commit 2ad0ac0e authored by xubaolin's avatar xubaolin Committed by GitHub

Draggable can be accepted when the data is null (#97355)

parent 9e7cc970
......@@ -16,9 +16,9 @@ class ExampleDragTarget extends StatefulWidget {
class ExampleDragTargetState extends State<ExampleDragTarget> {
Color _color = Colors.grey;
void _handleAccept(Color data) {
void _handleAccept(Color? data) {
setState(() {
_color = data;
_color = data!;
});
}
......@@ -215,7 +215,7 @@ class MovableBall extends StatelessWidget {
);
} else {
return DragTarget<bool>(
onAccept: (bool data) { callback(position); },
onAccept: (bool? data) { callback(position); },
builder: (BuildContext context, List<bool?> accepted, List<dynamic> rejected) {
return dashedBall;
},
......
......@@ -81,9 +81,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
),
);
},
onAccept: (int data) {
onAccept: (int? data) {
setState(() {
acceptedData += data;
acceptedData += data!;
});
},
),
......
......@@ -20,7 +20,7 @@ typedef DragTargetWillAccept<T> = bool Function(T? data);
/// Signature for causing a [DragTarget] to accept the given data.
///
/// Used by [DragTarget.onAccept].
typedef DragTargetAccept<T> = void Function(T data);
typedef DragTargetAccept<T> = void Function(T? data);
/// Signature for determining information about the acceptance by a [DragTarget].
///
......@@ -638,7 +638,7 @@ class DragTargetDetails<T> {
DragTargetDetails({required this.data, required this.offset}) : assert(offset != null);
/// The data that was dropped onto this [DragTarget].
final T data;
final T? data;
/// The global position when the specific pointer event occurred on
/// the draggable.
......@@ -767,14 +767,14 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
setState(() {
_candidateAvatars.remove(avatar);
});
widget.onAccept?.call(avatar.data! as T);
widget.onAcceptWithDetails?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
widget.onAccept?.call(avatar.data as T?);
widget.onAcceptWithDetails?.call(DragTargetDetails<T>(data: avatar.data as T?, offset: avatar._lastOffset!));
}
void didMove(_DragAvatar<Object> avatar) {
if (!mounted)
return;
widget.onMove?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
widget.onMove?.call(DragTargetDetails<T>(data: avatar.data as T?, offset: avatar._lastOffset!));
}
@override
......
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