relayout active ListWheelScrollView children every performLayout (#124476)
during performLayout, active children's constraints were updated, but they weren't laid out again w.r.t their parent (ListWheelScrollView). Fixes #123497
This commit is contained in:
@@ -763,8 +763,9 @@ class RenderListWheelViewport
|
||||
|
||||
// Relayout all active children.
|
||||
RenderBox? child = firstChild;
|
||||
int index = currentFirstIndex;
|
||||
while (child != null) {
|
||||
child.layout(childConstraints, parentUsesSize: true);
|
||||
_layoutChild(child, childConstraints, index++);
|
||||
child = childAfter(child);
|
||||
}
|
||||
|
||||
|
||||
@@ -604,6 +604,41 @@ void main() {
|
||||
// centered.
|
||||
expect(viewport.childCount, 13);
|
||||
});
|
||||
|
||||
testWidgets('Active children are laid out with correct offset', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/123497
|
||||
Future<void> buildWidget(double width) async {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: ListWheelScrollView(
|
||||
itemExtent: 100.0,
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: width,
|
||||
child: const Center(child: Text('blah')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double getSizedBoxWidth() => tester.getSize(find.byType(SizedBox)).width;
|
||||
double getSizedBoxCenterX() => tester.getCenter(find.byType(SizedBox)).dx;
|
||||
|
||||
await buildWidget(200.0);
|
||||
expect(getSizedBoxWidth(), 200.0);
|
||||
expect(getSizedBoxCenterX(), 400.0);
|
||||
|
||||
await buildWidget(100.0);
|
||||
expect(getSizedBoxWidth(), 100.0);
|
||||
expect(getSizedBoxCenterX(), 400.0);
|
||||
|
||||
await buildWidget(300.0);
|
||||
expect(getSizedBoxWidth(), 300.0);
|
||||
expect(getSizedBoxCenterX(), 400.0);
|
||||
});
|
||||
});
|
||||
|
||||
group('pre-transform viewport', () {
|
||||
|
||||
Reference in New Issue
Block a user