Skip to content

[DropdownMenu] keyboard Navigation broken when searchCallback is provided and some entry contains other entry #152375

@PurplePolyhedron

Description

@PurplePolyhedron

Steps to reproduce

Create a dropdown menu with some entry labels that contains other entry labels, with searchCallback provided.

Similar to #147253, but only when a searchCallback is provided.
Because the fix (#147294) was on the default search function.

Expected results

Arrow key can navigate

Actual results

Down arrow key cannot navigate to second item

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 MaterialApp(
      home: Scaffold(
        body: DropdownMenu<int>(
          searchCallback: (List<DropdownMenuEntry<int>> entries, String query) {
            if (query.isEmpty) {
              return null;
            }
            final int index = entries.indexWhere(
              (DropdownMenuEntry<int> entry) => entry.label.contains(query),
            );

            return index != -1 ? index : null;
          },
          dropdownMenuEntries: const <DropdownMenuEntry<int>>[
            DropdownMenuEntry<int>(value: 0, label: 'ABC'),
            DropdownMenuEntry<int>(value: 1, label: 'AB'),
            DropdownMenuEntry<int>(value: 2, label: 'ABCD'),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.24.0-1.0.pre.293, on macOS 14.5 23F79 darwin-arm64, locale en-AU)
    • Flutter version 3.24.0-1.0.pre.293 on channel master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ccd51a7f58 (2 hours ago), 2024-07-26 21:18:26 +0800
    • Engine revision 8714b54a87
    • Dart version 3.6.0 (build 3.6.0-83.0.dev)
    • DevTools version 2.37.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.team-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