fix DropdownMenu keyboard navigation when entries are filtered empty (#155252)

fixes https://github.com/flutter/flutter/issues/154532
This commit is contained in:
PurplePolyhedron 2024-10-02 13:46:23 +08:00 committed by GitHub
parent cc7f76cf35
commit ce2fe59bbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -807,6 +807,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
} else {
filteredEntries = widget.dropdownMenuEntries;
}
_menuHasEnabledItem = filteredEntries.any((DropdownMenuEntry<T> entry) => entry.enabled);
if (_enableSearch) {
if (widget.searchCallback != null) {

View File

@ -1315,6 +1315,28 @@ void main() {
expect(tester.takeException(), isNull);
});
// Regression test for https://github.com/flutter/flutter/issues/154532.
testWidgets('Searching for non matching item does not crash', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: DropdownMenu<TestMenu>(
enableFilter: true,
requestFocusOnTap: true,
dropdownMenuEntries: menuChildren,
),
),
));
// Open the menu.
await tester.tap(find.byType(DropdownMenu<TestMenu>));
await tester.pump();
await tester.enterText(find.byType(TextField).first, 'Me');
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField).first, 'Meu');
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
// Regression test for https://github.com/flutter/flutter/issues/147253.
testWidgets('Default search prioritises the current highlight on desktop platforms',
(WidgetTester tester) async {