Skip to content

CarouselView.weighted throws when given zero constraints #167621

@bleroux

Description

@bleroux

Steps to reproduce

  1. Run the code sample (debug or release mode. Without the zeroed SizedBox the issue is reproducible in release mode on Android).
  2. Observe the error log.

Expected results

No exception thrown.

Actual results

Several exceptions in the error log.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        // The issue is also reproducible without a zero width SixedBox.
        // In release mode, especially on Android, the initial viewport dimension
        // is usually zero.
        body: SizedBox(
          width: 0,
          child: CarouselView.weighted(
            flexWeights: <int>[1, 2],
            children: <Widget>[FlutterLogo(), FlutterLogo()],
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Logs

Logs
════════ Exception caught by rendering library ═════════════════════════════════
The following UnsupportedError was thrown during performLayout():
Unsupported operation: Infinity or NaN toInt

The relevant error-causing widget was:
    CarouselView CarouselView:file:///Users/bruno/Nevercode/investigationapp/lib/0%20-%20Investigate/Various/flutter_105630/flutter_105630_carousel_flutter_logo.dart:14:31

When the exception was thrown, this was the stack:
#0      double.toInt (dart:core-patch/double.dart)
#1      double.round (dart:core-patch/double.dart:196:34)
double.dart:196
#2      _RenderSliverWeightedCarousel._firstVisibleItemIndex (package:flutter/src/material/carousel.dart:918:69)
carousel.dart:918
#3      _RenderSliverWeightedCarousel.getMinChildIndexForScrollOffset (package:flutter/src/material/carousel.dart:981:21)
carousel.dart:981

Flutter Doctor output

Doctor output
[!] Flutter (Channel master, 3.32.0-1.0.pre.200, on macOS 14.2.1 23C71 darwin-arm64, locale fr-FR)
    ! Upstream repository [email protected]:bleroux/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to [email protected]:bleroux/flutter.git to dismiss
      this error.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 15.1)
    ! CocoaPods 1.11.3 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see
      https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.99.3)
[✓] Connected device (2 available)
[✓] Network resources

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkf: material designflutter/packages/flutter/material repository.found in release: 3.29Found to occur in 3.29found in release: 3.32Found to occur in 3.32frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions