Skip to content

Commit c0b28f6

Browse files
authored
[material_ui] Fix SliverGeometry maxPaintExtent assertion in CarouselView.weighted (#12563)
Closes flutter/flutter#188380 Port of flutter/flutter#188381. ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 2c91ffe commit c0b28f6

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎packages/material_ui/lib/src/carousel.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ class _RenderSliverWeightedCarousel extends RenderSliverFixedExtentBoxAdaptor {
14401440
_buildItemExtent(lastIndex, layoutDimensions),
14411441
);
14421442
trailingScrollOffset += extraLayoutOffset;
1443+
estimatedMaxScrollOffset = trailingScrollOffset;
14431444
} else {
14441445
trailingScrollOffset = indexToLayoutOffset(deprecatedExtraItemExtent, lastIndex + 1);
14451446
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes SliverGeometry maxPaintExtent assertion in CarouselView.weighted
3+
version: patch

‎packages/material_ui/test/carousel_test.dart‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,39 @@ void main() {
29652965

29662966
expect(position.pixels, 0.0);
29672967
});
2968+
2969+
testWidgets('CarouselView.weighted does not crash at finite trailing scroll offset', (
2970+
WidgetTester tester,
2971+
) async {
2972+
final controller = CarouselController();
2973+
addTearDown(controller.dispose);
2974+
2975+
// Set the exact viewport size that caused the crash: 750 main axis extent.
2976+
await tester.binding.setSurfaceSize(const Size(750, 1000));
2977+
addTearDown(() => tester.binding.setSurfaceSize(null));
2978+
2979+
await tester.pumpWidget(
2980+
MaterialApp(
2981+
home: Scaffold(
2982+
body: CarouselView.weighted(
2983+
controller: controller,
2984+
flexWeights: const <int>[1, 7],
2985+
children: List<Widget>.generate(5, (index) => const FlutterLogo()),
2986+
),
2987+
),
2988+
),
2989+
);
2990+
2991+
expect(tester.takeException(), isNull);
2992+
2993+
// Jump exactly to the scroll offset from the crash log (461.5)
2994+
// to trigger the boundary geometry layout logic calculation.
2995+
controller.jumpTo(461.5);
2996+
await tester.pump();
2997+
2998+
// Verify no SliverGeometry exception was thrown.
2999+
expect(tester.takeException(), isNull);
3000+
});
29683001
}
29693002

29703003
Finder getItem(int index) {

0 commit comments

Comments
 (0)