Skip to content

[DropdownMenu] Filters are reset when traversing using keyboard  #165867

@ahmedrasar

Description

@ahmedrasar

Steps to reproduce

  1. Create a DropdownMenu with enableFilter set to true
  2. Provide a list dropdownMenuEntries
  3. Search for a value that matches more than one value in the entries list
  4. Traverse using the up/down arrow keys

Expected results

Up/down keys should only traverse the filtered list.

Actual results

The original list is loaded, and the text field mismatches the highlighted entry.

Code sample

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

void main() {
  runApp(const FruitDropdownApp());
}

class FruitDropdownApp extends StatelessWidget {
  const FruitDropdownApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fruit Dropdown Demo',
      theme: ThemeData(primarySwatch: Colors.green),
      home: const FruitDropdownPage(),
    );
  }
}

class FruitDropdownPage extends StatefulWidget {
  const FruitDropdownPage({Key? key}) : super(key: key);

  @override
  _FruitDropdownPageState createState() => _FruitDropdownPageState();
}

class _FruitDropdownPageState extends State<FruitDropdownPage> {
  // List of similar fruits (berries in this case)
  final List<String> berryFruits = [
    'Strawberry',
    'Blueberry',
    'Raspberry',
    'Blackberry',
    'Cranberry',
    'Gooseberry',
    'Boysenberry',
  ];

  // Variable to store the selected fruit
  String? selectedFruit;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Berry Fruits Dropdown')),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              DropdownMenu<String>(
                width: 300,
                enableFilter: true,
                label: const Text('Select a Berry'),
                initialSelection: berryFruits.first,
                onSelected: (String? newValue) {
                  setState(() {
                    selectedFruit = newValue;
                  });
                },
                dropdownMenuEntries:
                    berryFruits.map<DropdownMenuEntry<String>>((String fruit) {
                      return DropdownMenuEntry<String>(
                        value: fruit,
                        label: fruit,
                      );
                    }).toList(),
              ),
              const SizedBox(height: 20),
              Text(
                selectedFruit != null
                    ? 'Selected Fruit: $selectedFruit'
                    : 'No fruit selected',
                style: const TextStyle(fontSize: 18),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

2025-03-25.09-45-28.mp4

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.31.0-1.0.pre.215, on Microsoft Windows [Version 10.0.26100.3476], locale en-US) [3.4s]
    • Flutter version 3.31.0-1.0.pre.215 on channel master at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 26037dff87 (11 hours ago), 2025-03-24 13:11:13 -0700
    • Engine revision 26037dff87
    • Dart version 3.8.0 (build 3.8.0-221.0.dev)
    • DevTools version 2.45.0-dev.0

[✓] Windows Version (11 Home 64-bit, 24H2, 2009) [2.8s]

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.2s]
    • Android SDK at C:\Users\ahmed\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Users\ahmed\AppData\Local\Programs\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [165ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.1) [164ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.11.35219.272
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2023.2) [17ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 Java(TM) SE Runtime Environment (build 21.0.4+8-LTS-274)

[✓] Android Studio (version 2024.2) [15ms]
    • Android Studio at C:\Users\ahmed\AppData\Local\Programs\Android Studio
    • 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 21.0.3+-12282718-b509.11)

[✓] VS Code (version 1.98.2) [15ms]
    • VS Code at C:\Users\ahmed\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.106.0

[✓] Connected device (3 available) [174ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.3476]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 134.0.6998.118
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 134.0.3124.83

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31frameworkflutter/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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions