Skip to content

DropdownMenu filtering is broken (after selecting an item, it reverts to a different value) #174609

Closed

Description

@Hixie

Steps to reproduce

  1. Run the code sample below (it works in dartpad).
  2. Click the text field.
  3. Type "a".
  4. Select the third option, "Dragonfruit".

Expected results

It should say "Dragonfruit".

Actual results

It says "Cherry"!

Code sample

import 'package:flutter/material.dart';

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

final List<DropdownMenuEntry<String>> entries = [
  DropdownMenuEntry<String>(value: 'Apple', label: 'Apple'),
  DropdownMenuEntry<String>(value: 'Banana', label: 'Banana'),
  DropdownMenuEntry<String>(value: 'Cherry', label: 'Cherry'),
  DropdownMenuEntry<String>(value: 'Dragonfruit', label: 'Dragonfruit'),
];

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

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

class _DropdownMenuExampleState extends State<DropdownMenuExample> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Material(
        child: DropdownMenu<String>(
          enableFilter: true,
          onSelected: (String? icon) {
            setState(() { });
          },
          dropdownMenuEntries: entries.toList(),
        ),
      ),
    );
  }
}

This regressed in #162062.

Activity

  1. pranataprojects commented on Aug 28, 2025

    @pranataprojects

    Hi @Hixie , I ran into the same issue and found a workaround. The problem is that DropdownMenu doesn’t consistently keep the selected value after filtering unless you manage the selection explicitly.

    You can fix it by holding the current selection in state and passing it back to the widget via initialSelection. For example:

    class _DropdownMenuExampleState extends State<DropdownMenuExample> {
      String? selectedValue;
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: Center(
              child: DropdownMenu<String>(
                initialSelection: selectedValue,
                enableFilter: true,
                onSelected: (String? value) {
                  setState(() {
                    selectedValue = value;
                  });
                },
                dropdownMenuEntries: entries,
              ),
            ),
          ),
        );
      }
    }
    
    

    With this, selecting “Dragonfruit” will remain stable instead of reverting to “Cherry.”

  2. tirth-patel-nc commented on Aug 28, 2025

    @tirth-patel-nc
    Member

    @Hixie Thanks for the report. Seeing the same behaviour with latest SDK versions with provided code sample & steps. It doesn't replicate on 3.32.8 hence marking it as a regression.

    @pranataprojects thanks for the workaround.

    stable : 3.35.2
    master : 3.36.0-1.0.pre-305
    

    3.32.8 (WAI)

    Screen.Recording.2025-08-28.at.5.18.17.PM.mov

    3.35.2, 3.36.0-1.0.pre-305 (Issue)

    Screen.Recording.2025-08-28.at.5.17.39.PM.mov
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    team-designOwned by Design Languages team
    p: material_uimaterial_ui package in flutter/packages
    c: regressionIt was better in the past than it is now
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    workaround availableThere is a workaround available to overcome the issue
    and removed
    in triagePresently being triaged by the triage team
    on Aug 28, 2025
  4. self-assigned this
    on Aug 28, 2025
  5. ahmedrasar commented on Aug 30, 2025

    @ahmedrasar
    Contributor

    I filed a fix in #174757.

    I had to work around some edgy use cases in the original PR, I must have been consumed so that little detail have slipped by. Sorry for that.

  6. removed their assignment
    on Sep 2, 2025
  7. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Sep 3, 2025
  8. github-actions commented on Nov 10, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowfound in release: 3.35Found to occur in 3.35found in release: 3.36Found to occur in 3.36frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions