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:
parent
d238834bee
commit
57d2a20be3
@ -411,6 +411,7 @@ class ReorderableListState extends State<ReorderableList> {
|
|||||||
itemExtent: widget.itemExtent,
|
itemExtent: widget.itemExtent,
|
||||||
prototypeItem: widget.prototypeItem,
|
prototypeItem: widget.prototypeItem,
|
||||||
itemBuilder: widget.itemBuilder,
|
itemBuilder: widget.itemBuilder,
|
||||||
|
itemExtentBuilder: widget.itemExtentBuilder,
|
||||||
itemCount: widget.itemCount,
|
itemCount: widget.itemCount,
|
||||||
onReorder: widget.onReorder,
|
onReorder: widget.onReorder,
|
||||||
onReorderStart: widget.onReorderStart,
|
onReorderStart: widget.onReorderStart,
|
||||||
|
@ -923,6 +923,51 @@ void main() {
|
|||||||
), throwsAssertionError);
|
), 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 {
|
testWidgets('SliverReorderableList asserts on both non-null itemExtent and prototypeItem', (WidgetTester tester) async {
|
||||||
final List<int> numbers = <int>[0,1,2];
|
final List<int> numbers = <int>[0,1,2];
|
||||||
expect(() => SliverReorderableList(
|
expect(() => SliverReorderableList(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user