mirror of
https://github.com/flutter/flutter
synced 2024-10-04 07:19:46 +00:00
Add assertion of recordable list (#76272)
This commit is contained in:
parent
5ab3474435
commit
43e3328e98
|
@ -457,6 +457,14 @@ class _ReorderableListContentState extends State<_ReorderableListContent> {
|
|||
|
||||
Widget _itemBuilder(BuildContext context, int 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
|
||||
// _ReorderableItem so the widget versions can have them as well.
|
||||
|
|
|
@ -1326,6 +1326,22 @@ void main() {
|
|||
}
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue