fix ReorderableList not passing in item extent builder (#155994)

This PR fixes the `ReorderableList` in `flutter/widgets.dart` not passing the item extent builder to the underlying SliverReorderableList. I double checked and the material equivalent is working as intended.

Fixes https://github.com/flutter/flutter/issues/155936

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
Navaron Bracke 2024-10-02 19:18:21 +02:00 committed by GitHub
parent d238834bee
commit 57d2a20be3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View File

@ -411,6 +411,7 @@ class ReorderableListState extends State<ReorderableList> {
itemExtent: widget.itemExtent,
prototypeItem: widget.prototypeItem,
itemBuilder: widget.itemBuilder,
itemExtentBuilder: widget.itemExtentBuilder,
itemCount: widget.itemCount,
onReorder: widget.onReorder,
onReorderStart: widget.onReorderStart,

View File

@ -923,6 +923,51 @@ void main() {
), throwsAssertionError);
});
testWidgets('ReorderableList passes itemExtentBuilder to SliverReorderableList', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/155936
const int itemCount = 5;
const List<double> items = <double>[10.0, 20.0, 30.0, 40.0, 50.0];
void handleReorder(int fromIndex, int toIndex) {
if (toIndex > fromIndex) {
toIndex -= 1;
}
items.insert(toIndex, items.removeAt(fromIndex));
}
// The list has five elements, that indicate the extent for the item at the given index.
await tester.pumpWidget(
MaterialApp(
home: ReorderableList(
itemBuilder: (BuildContext context, int index) => SizedBox(
key: ValueKey<double>(items[index]),
child: Text('Item $index'),
),
itemCount: itemCount,
onReorder: handleReorder,
itemExtentBuilder: (int index, SliverLayoutDimensions dimensions) {
return items[index];
},
),
),
);
const Map<int, double> expectedExtents = <int, double>{
0: 10.0,
1: 20.0,
2: 30.0,
3: 40.0,
4: 50.0,
};
final Map<int, double> itemExtents = <int, double>{
for (int i = 0; i < itemCount; i++)
i: tester.getSize(find.text('Item $i')).height,
};
expect(const MapEquality<int, double>().equals(itemExtents, expectedExtents), isTrue);
});
testWidgets('SliverReorderableList asserts on both non-null itemExtent and prototypeItem', (WidgetTester tester) async {
final List<int> numbers = <int>[0,1,2];
expect(() => SliverReorderableList(