Update adaptable_page_view.dart (#2134)

Co-authored-by: Matthew Fosse <matt@fosse.co>

Serhii committed Mar 29, 2025 at 00:08 UTC 869c5a83cff6701c9e3d6c75281c9c27f9275432
1 file changed +18 -3
lib/src/widgets/adaptable_page_view.dart
+18 -3
@@ -137,10 +137,25 @@ class _RenderSizingContainer extends RenderProxyBox {
137 parentUsesSize: true,
138 );
139
140 - final a = sizes[page.floor()]!;
141 - final b = sizes[page.ceil()]!;
140 + final int floorPage = page.floor();
141 + final int ceilPage = page.ceil();
142 +
143 + Size? a = sizes[floorPage];
144 + Size? b = sizes[ceilPage];
145 +
146 + if (a == null && sizes.isNotEmpty) {
147 + a = sizes.values.first;
148 + }
149 + if (b == null && sizes.isNotEmpty) {
150 + b = sizes.values.first;
151 + }
152 +
153 + a ??= child.getDryLayout(constraints);
154 + b ??= a;
155 +
156 + final double t = (page - floorPage).clamp(0.0, 1.0);
157 + final double height = lerpDouble(a.height, b.height, t) ?? a.height;
158
143 - final height = lerpDouble(a.height, b.height, page - page.floor());
159
160 child.layout(
161 constraints.copyWith(minHeight: height, maxHeight: height),