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