Unverified Commit f8eee10f authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Revert "Draggable can be accepted when the data is null" (#99419)

parent 4b20ce74
...@@ -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
......
...@@ -39,9 +39,7 @@ void main() { ...@@ -39,9 +39,7 @@ void main() {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onMove: (_) => moveCount++, onMove: (_) => moveCount++,
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -93,60 +91,9 @@ void main() { ...@@ -93,60 +91,9 @@ void main() {
expect(moveCount, 1); expect(moveCount, 1);
}); });
testWidgets('Draggable can be accepted when the data is null', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/84816
final Map<String, int?> receivedData = <String, int?>{};
await tester.pumpWidget(MaterialApp(
home: Column(
children: <Widget>[
const Draggable<int>(
feedback: Text('Dragging'),
child: Text('Source'),
),
DragTarget<int>(
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target 1'));
},
onWillAccept: (int? data) {
receivedData['onWillAccept'] = data;
return true;
},
onAccept: (int? data) {
receivedData['onAccept'] = data;
},
onAcceptWithDetails: (DragTargetDetails<int> details) {
receivedData['onAcceptWithDetails'] = details.data;
},
onMove: (DragTargetDetails<int> details) {
receivedData['onMove'] = details.data;
},
),
],
),
));
final Offset firstLocation = tester.getCenter(find.text('Source'));
final TestGesture gesture = await tester.startGesture(firstLocation, pointer: 7);
await tester.pump();
final Offset secondLocation = tester.getCenter(find.text('Target 1'));
await gesture.moveTo(secondLocation);
await tester.pump();
await gesture.up();
await tester.pump();
expect(receivedData.length, 4);
expect(receivedData['onWillAccept'], null);
expect(receivedData['onMove'], null);
expect(receivedData['onAccept'], null);
expect(receivedData['onAcceptWithDetails'], null);
});
// Regression test for https://github.com/flutter/flutter/issues/76825 // Regression test for https://github.com/flutter/flutter/issues/76825
testWidgets('Drag and drop - onLeave callback fires correctly with generic parameter', (WidgetTester tester) async { testWidgets('Drag and drop - onLeave callback fires correctly with generic parameter', (WidgetTester tester) async {
final Map<String, int> leftBehind = <String, int>{ final Map<String,int> leftBehind = <String,int>{
'Target 1': 0, 'Target 1': 0,
'Target 2': 0, 'Target 2': 0,
}; };
...@@ -221,7 +168,7 @@ void main() { ...@@ -221,7 +168,7 @@ void main() {
}); });
testWidgets('Drag and drop - onLeave callback fires correctly', (WidgetTester tester) async { testWidgets('Drag and drop - onLeave callback fires correctly', (WidgetTester tester) async {
final Map<String, int> leftBehind = <String, int>{ final Map<String,int> leftBehind = <String,int>{
'Target 1': 0, 'Target 1': 0,
'Target 2': 0, 'Target 2': 0,
}; };
...@@ -297,7 +244,7 @@ void main() { ...@@ -297,7 +244,7 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/76825 // Regression test for https://github.com/flutter/flutter/issues/76825
testWidgets('Drag and drop - onMove callback fires correctly with generic parameter', (WidgetTester tester) async { testWidgets('Drag and drop - onMove callback fires correctly with generic parameter', (WidgetTester tester) async {
final Map<String, int> targetMoveCount = <String, int>{ final Map<String,int> targetMoveCount = <String,int>{
'Target 1': 0, 'Target 1': 0,
'Target 2': 0, 'Target 2': 0,
}; };
...@@ -316,7 +263,7 @@ void main() { ...@@ -316,7 +263,7 @@ void main() {
}, },
onMove: (DragTargetDetails<int> details) { onMove: (DragTargetDetails<int> details) {
targetMoveCount['Target 1'] = targetMoveCount['Target 1'] =
targetMoveCount['Target 1']! + details.data!; targetMoveCount['Target 1']! + details.data;
}, },
), ),
DragTarget<int>( DragTarget<int>(
...@@ -325,7 +272,7 @@ void main() { ...@@ -325,7 +272,7 @@ void main() {
}, },
onMove: (DragTargetDetails<int> details) { onMove: (DragTargetDetails<int> details) {
targetMoveCount['Target 2'] = targetMoveCount['Target 2'] =
targetMoveCount['Target 2']! + details.data!; targetMoveCount['Target 2']! + details.data;
}, },
), ),
], ],
...@@ -370,7 +317,7 @@ void main() { ...@@ -370,7 +317,7 @@ void main() {
}); });
testWidgets('Drag and drop - onMove callback fires correctly', (WidgetTester tester) async { testWidgets('Drag and drop - onMove callback fires correctly', (WidgetTester tester) async {
final Map<String, int> targetMoveCount = <String, int>{ final Map<String,int> targetMoveCount = <String,int>{
'Target 1': 0, 'Target 1': 0,
'Target 2': 0, 'Target 2': 0,
}; };
...@@ -1220,9 +1167,7 @@ void main() { ...@@ -1220,9 +1167,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1298,9 +1243,7 @@ void main() { ...@@ -1298,9 +1243,7 @@ void main() {
); );
}, },
onWillAccept: (int? data) => false, onWillAccept: (int? data) => false,
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1373,9 +1316,7 @@ void main() { ...@@ -1373,9 +1316,7 @@ void main() {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onWillAccept: (int? data) => false, onWillAccept: (int? data) => false,
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
]), ]),
...@@ -1425,9 +1366,7 @@ void main() { ...@@ -1425,9 +1366,7 @@ void main() {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onWillAccept: (int? data) => false, onWillAccept: (int? data) => false,
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1641,9 +1580,7 @@ void main() { ...@@ -1641,9 +1580,7 @@ void main() {
); );
}, },
onWillAccept: (int? data) => false, onWillAccept: (int? data) => false,
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1711,9 +1648,7 @@ void main() { ...@@ -1711,9 +1648,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1854,9 +1789,7 @@ void main() { ...@@ -1854,9 +1789,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -1934,9 +1867,7 @@ void main() { ...@@ -1934,9 +1867,7 @@ void main() {
), ),
); );
}, },
onAccept: (int? data) { onAccept: acceptedInts.add,
acceptedInts.add(data!);
},
onAcceptWithDetails: acceptedIntsDetails.add, onAcceptWithDetails: acceptedIntsDetails.add,
), ),
DragTarget<double>( DragTarget<double>(
...@@ -1948,9 +1879,7 @@ void main() { ...@@ -1948,9 +1879,7 @@ void main() {
), ),
); );
}, },
onAccept: (double? data) { onAccept: acceptedDoubles.add,
acceptedDoubles.add(data!);
},
onAcceptWithDetails: acceptedDoublesDetails.add, onAcceptWithDetails: acceptedDoublesDetails.add,
), ),
], ],
...@@ -2066,9 +1995,7 @@ void main() { ...@@ -2066,9 +1995,7 @@ void main() {
child: Text('Target1'), child: Text('Target1'),
), ),
); );
}, onAccept: (DragTargetData? data) { }, onAccept: acceptedDragTargetDatas.add,
acceptedDragTargetDatas.add(data!);
},
onAcceptWithDetails: acceptedDragTargetDataDetails.add, onAcceptWithDetails: acceptedDragTargetDataDetails.add,
), ),
DragTarget<ExtendedDragTargetData>( DragTarget<ExtendedDragTargetData>(
...@@ -2080,9 +2007,7 @@ void main() { ...@@ -2080,9 +2007,7 @@ void main() {
), ),
); );
}, },
onAccept: (ExtendedDragTargetData? data) { onAccept: acceptedExtendedDragTargetDatas.add,
acceptedExtendedDragTargetDatas.add(data!);
},
onAcceptWithDetails: acceptedExtendedDragTargetDataDetails.add, onAcceptWithDetails: acceptedExtendedDragTargetDataDetails.add,
), ),
], ],
...@@ -2132,9 +2057,7 @@ void main() { ...@@ -2132,9 +2057,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -2393,9 +2316,7 @@ void main() { ...@@ -2393,9 +2316,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -2425,9 +2346,7 @@ void main() { ...@@ -2425,9 +2346,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -2507,9 +2426,7 @@ void main() { ...@@ -2507,9 +2426,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -2594,9 +2511,7 @@ void main() { ...@@ -2594,9 +2511,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
...@@ -2850,9 +2765,7 @@ void main() { ...@@ -2850,9 +2765,7 @@ void main() {
builder: (BuildContext context, List<Object?> data, List<dynamic> rejects) { builder: (BuildContext context, List<Object?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (Object? data) { onAccept: accepted.add,
accepted.add(data!);
},
), ),
], ],
), ),
...@@ -2888,9 +2801,7 @@ void main() { ...@@ -2888,9 +2801,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
), ),
], ],
), ),
...@@ -2926,9 +2837,7 @@ void main() { ...@@ -2926,9 +2837,7 @@ void main() {
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onWillAccept: (int? data) { onWillAccept: (int? data) {
if (data == null) if (data == null)
isReceiveNullDataForCheck = true; isReceiveNullDataForCheck = true;
...@@ -3271,9 +3180,7 @@ Future<void> _testChildAnchorFeedbackPosition({ required WidgetTester tester, do ...@@ -3271,9 +3180,7 @@ Future<void> _testChildAnchorFeedbackPosition({ required WidgetTester tester, do
builder: (BuildContext context, List<int?> data, List<dynamic> rejects) { builder: (BuildContext context, List<int?> data, List<dynamic> rejects) {
return const SizedBox(height: 100.0, child: Text('Target')); return const SizedBox(height: 100.0, child: Text('Target'));
}, },
onAccept: (int? data) { onAccept: accepted.add,
accepted.add(data!);
},
onAcceptWithDetails: acceptedDetails.add, onAcceptWithDetails: acceptedDetails.add,
), ),
], ],
......
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