Repository: flutter
Issue: `CarouselView` throws `AssertionError` when parent size is 0
Labels: c: crash,framework,f: material design,waiting for PR to land (fixed),has reproducible steps,P2,team-design,triaged-design,found in release: 3.27,found in release: 3.28

### Steps to reproduce

1. Run the code sample
2. Note that there is an error in the console

### Expected results

`CarouselView` should not throw when parent size is 0.

### Actual results

`CarouselView` throws an `AssertionError` when parent size is 0.

The documentation for the `itemExtent` property mentions that _the item extent should not exceed the available space that the carousel view occupies to ensure at least one item is fully visible_. However, the same error is thrown when both the `SizedBox` and `itemExtent` is set to 0. I would also argue that the widget should gracefully handle having 0 size since this can happen indirectly through the parent widget size.

Additionally, an `UnsupportedError` (`Unsupported operation: Infinity or NaN toInt`) is thrown when the `SizedBox` size is set to 100 and `itemExtent` is set to 0.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SizedBox(
          width: 0,
          child: CarouselView(
            itemExtent: 100,
            children: [
              Container(
                color: Colors.red,
                width: 100,
                height: 100,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

```

</details>

### Logs

<details open><summary>Logs</summary>

```console
Launching lib/main.dart on iPhone 15 Pro in debug mode...
Xcode build done.                                           14.2s
Connecting to VM Service at ws://127.0.0.1:64008/DOq4En-aJYE=/ws
Connected to the VM Service.

════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1515 pos 12: 'correctedOffset.isFinite': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
    CarouselView CarouselView

When the exception was thrown, this was the stack:
#2      RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1515:12)
#3      RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1467:20)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#5      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#6      RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#7      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#8      RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#9      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#10     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#11     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#12     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#13     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#14     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#15     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#16     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#17     _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:393:14)
#18     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#19     RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:293:14)
#20     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#21     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:180:12)
#22     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1118:7)
#23     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:249:7)
#24     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:419:14)
#25     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#26     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#27     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#28     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#29     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1483:11)
#30     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#31     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#32     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#33     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#34     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#35     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#36     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#37     ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:62:11)
#38     RenderStack._computeSize (package:flutter/src/rendering/stack.dart:646:43)
#39     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:673:12)
#40     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#42     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#44     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#46     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#47     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#48     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#49     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#50     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#51     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#52     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3750:13)
#53     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#54     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#55     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#56     _RenderTheaterMixin.layoutChild (package:flutter/src/widgets/overlay.dart:1076:13)
#57     _RenderTheater.performLayout (package:flutter/src/widgets/overlay.dart:1422:9)
#58     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#59     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#60     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#61     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#62     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#63     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#64     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#65     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#66     RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:574:11)
#67     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#68     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#69     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#70     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#71     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#72     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#73     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#74     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#75     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#76     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#77     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#78     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#79     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#80     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:18)
#81     RenderObject.layout (package:flutter/src/rendering/object.dart:2715:7)
#82     RenderView.performLayout (package:flutter/src/rendering/view.dart:294:12)
#83     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2548:7)
#84     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1112:18)
#85     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1125:15)
#86     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:617:23)
#87     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1231:13)
#88     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:483:5)
#89     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1442:15)
#90     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1355:9)
#91     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1064:9)
#92     PlatformDispatcher.scheduleWarmUpFrame.<anonymous closure> (dart:ui/platform_dispatcher.dart:873:16)
#96     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)

The following RenderObject was being processed when the exception was fired: RenderViewport#74279 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    needs compositing
    parentData: <none> (can use size)
    constraints: BoxConstraints(w=0.0, 0.0<=h<=852.0)
    size: Size(0.0, 852.0)
    axisDirection: right
    crossAxisDirection: down
    offset: _CarouselPosition#7e9dc(offset: NaN, range: null..null, viewport: 0.0, ScrollableState, BouncingScrollPhysics -> RangeMaintainingScrollPhysics -> BouncingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#a8b19, ScrollDirection.idle)
    anchor: 0.0
    center child: _RenderSliverFixedExtentCarousel#5c1a8 NEEDS-LAYOUT NEEDS-PAINT
        parentData: paintOffset=Offset(0.0, 0.0)
        constraints: MISSING
        geometry: null
        no children current live
RenderObject: RenderViewport#74279 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    needs compositing
    parentData: <none> (can use size)
    constraints: BoxConstraints(w=0.0, 0.0<=h<=852.0)
    size: Size(0.0, 852.0)
    axisDirection: right
    crossAxisDirection: down
    offset: _CarouselPosition#7e9dc(offset: NaN, range: null..null, viewport: 0.0, ScrollableState, BouncingScrollPhysics -> RangeMaintainingScrollPhysics -> BouncingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#a8b19, ScrollDirection.idle)
    anchor: 0.0
    center child: _RenderSliverFixedExtentCarousel#5c1a8 NEEDS-LAYOUT NEEDS-PAINT
        parentData: paintOffset=Offset(0.0, 0.0)
        constraints: MISSING
        geometry: null
        no children current live
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel main, 3.28.0-2.0.pre.38555, on macOS 14.4.1 23E224 darwin-arm64, locale en-SE)
    • Flutter version 3.28.0-2.0.pre.38555 on channel main
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 181f4244b4 (3 hours ago), 2024-12-20 18:46:55 +0100
    • Engine revision 181f4244b4
    • Dart version 3.7.0 (build 3.7.0-266.0.dev)
    • DevTools version 2.41.0
```

</details>