Skip to content

Commit 3ba249a

Browse files
authored
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
1 parent 4075503 commit 3ba249a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/flutter/lib/src/rendering/list_wheel_viewport.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,9 @@ class RenderListWheelViewport
763763

764764
// Relayout all active children.
765765
RenderBox? child = firstChild;
766+
int index = currentFirstIndex;
766767
while (child != null) {
767-
child.layout(childConstraints, parentUsesSize: true);
768+
_layoutChild(child, childConstraints, index++);
768769
child = childAfter(child);
769770
}
770771

packages/flutter/test/widgets/list_wheel_scroll_view_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,41 @@ void main() {
604604
// centered.
605605
expect(viewport.childCount, 13);
606606
});
607+
608+
testWidgets('Active children are laid out with correct offset', (WidgetTester tester) async {
609+
// Regression test for https://github.com/flutter/flutter/issues/123497
610+
Future<void> buildWidget(double width) async {
611+
return tester.pumpWidget(
612+
Directionality(
613+
textDirection: TextDirection.ltr,
614+
child: ListWheelScrollView(
615+
itemExtent: 100.0,
616+
children: <Widget>[
617+
SizedBox(
618+
width: width,
619+
child: const Center(child: Text('blah')),
620+
),
621+
],
622+
),
623+
),
624+
);
625+
}
626+
627+
double getSizedBoxWidth() => tester.getSize(find.byType(SizedBox)).width;
628+
double getSizedBoxCenterX() => tester.getCenter(find.byType(SizedBox)).dx;
629+
630+
await buildWidget(200.0);
631+
expect(getSizedBoxWidth(), 200.0);
632+
expect(getSizedBoxCenterX(), 400.0);
633+
634+
await buildWidget(100.0);
635+
expect(getSizedBoxWidth(), 100.0);
636+
expect(getSizedBoxCenterX(), 400.0);
637+
638+
await buildWidget(300.0);
639+
expect(getSizedBoxWidth(), 300.0);
640+
expect(getSizedBoxCenterX(), 400.0);
641+
});
607642
});
608643

609644
group('pre-transform viewport', () {

0 commit comments

Comments
 (0)