Skip to content

When filteredEntries isEmpty, a RangeError is thrown #152079

@zeqinjie

Description

@zeqinjie

Steps to reproduce

Click the DropdownMenu component to display the Menu
When the enableFilter is true and an initialSelection, entering multiple texts the filteredEntries isEmpty will throw RangeError.

Expected results

no RangeError throw

Actual results

will throw RangeError.

Code sample

Code sample
class TestMenu {
  final String label;

  const TestMenu(this.label);
}

final List<TestMenu> entries = [const TestMenu("A"), const TestMenu("B"), const TestMenu("C")];

class DropdownMenuExample extends StatefulWidget {
  const DropdownMenuExample({
    super.key,
  });

  @override
  State<DropdownMenuExample> createState() => _DropdownMenuExample4State();
}

class _DropdownMenuExampleState extends State<DropdownMenuExample4> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('DropdownMenu test'),
            DropdownMenu<TestMenu>(
              label: const Text('Test Menu'),
              dropdownMenuEntries: entries
                  .map(
                      (e) => DropdownMenuEntry<TestMenu>(value: e, label: e.label))
                  .toList(),
              enableFilter: true,
              initialSelection: entries[1],
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration iShot_2024-07-21_15 04 03

Logs

Logs
Actual: RangeError:<RangeError (length): Invalid value: Valid value range is empty: 0>

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.5 23F79 darwin-arm64, locale
    zh-Hans-CN)
    • Flutter version 3.19.3 on channel stable at
      /Users/zhengzeqin/fvm/versions/3.19.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (5 months ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/zhengzeqin/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/zhengzeqin/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.91.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.92.0

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5556                        •
      android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 15 Pro Max (mobile)  • D18E077D-192A-4AF6-B036-521FB2E45576 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)             • macos                                •
      darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                • chrome                               •
      web-javascript • Google Chrome 126.0.6478.183
    ! Error: Browsing on the local area network for 郑泽钦的iPhone. Ensure the
      device is unlocked and attached with a cable or associated with the same
      local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: error messageError messages from the Flutter frameworkc: crashStack traces logged to the consolef: material designflutter/packages/flutter/material repository.found in release: 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: duplicateIssue is closed as a duplicate of an existing issueteam-designOwned by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions