Unverified Commit 43e3328e authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Add assertion of recordable list (#76272)

parent 5ab34744
...@@ -457,6 +457,14 @@ class _ReorderableListContentState extends State<_ReorderableListContent> { ...@@ -457,6 +457,14 @@ class _ReorderableListContentState extends State<_ReorderableListContent> {
Widget _itemBuilder(BuildContext context, int index) { Widget _itemBuilder(BuildContext context, int index) {
final Widget item = widget.itemBuilder(context, index); final Widget item = widget.itemBuilder(context, index);
assert(() {
if (item.key == null) {
throw FlutterError(
'Every item of ReorderableListView must have a key.'
);
}
return true;
}());
// TODO(goderbauer): The semantics stuff should probably happen inside // TODO(goderbauer): The semantics stuff should probably happen inside
// _ReorderableItem so the widget versions can have them as well. // _ReorderableItem so the widget versions can have them as well.
......
...@@ -1326,6 +1326,22 @@ void main() { ...@@ -1326,6 +1326,22 @@ void main() {
} }
expect(items.take(8), orderedEquals(<int>[0, 1, 2, 3, 4, 5, 6, 7])); expect(items.take(8), orderedEquals(<int>[0, 1, 2, 3, 4, 5, 6, 7]));
}); });
testWidgets('ReorderableListView throws an error when key is not passed to its children', (WidgetTester tester) async {
final Widget reorderableListView = ReorderableListView.builder(
itemBuilder: (BuildContext context, int index) {
return SizedBox(child: Text('Item $index'));
},
itemCount: 3,
onReorder: (int oldIndex, int newIndex) { },
);
await tester.pumpWidget(MaterialApp(
home: reorderableListView,
));
final dynamic exception = tester.takeException();
expect(exception, isFlutterError);
expect(exception.toString(), contains('Every item of ReorderableListView must have a key.'));
});
} }
Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async { Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async {
......
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