Unverified Commit c65cab8f authored by Sabin Neupane's avatar Sabin Neupane Committed by GitHub

[DropdownMenu] Close menu after editing is complete (#130710)

Fixes: #130674 

Before: The dropdown menu was not closed if empty text was provided

After: The dropdown menu is closed even if empty text is provided

https://github.com/flutter/flutter/assets/61322712/fccac501-9fca-4f60-8a94-abfc50552ec9

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
parent 43afac1e
......@@ -612,9 +612,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
if (!widget.enableSearch) {
currentHighlight = null;
}
if (_textEditingController.text.isNotEmpty) {
controller.close();
}
},
onTap: () {
handlePressed(controller);
......
......@@ -1050,6 +1050,34 @@ void main() {
expect(controller.text, 'New Item');
});
testWidgets('The menu should be closed after text editing is complete', (WidgetTester tester) async {
final ThemeData themeData = ThemeData();
final TextEditingController controller = TextEditingController();
await tester.pumpWidget(MaterialApp(
theme: themeData,
home: Scaffold(
body: DropdownMenu<TestMenu>(
requestFocusOnTap: true,
enableFilter: true,
dropdownMenuEntries: menuChildren,
controller: controller,
),
),
));
// Access the MenuAnchor
final MenuAnchor menuAnchor = tester.widget<MenuAnchor>(find.byType(MenuAnchor));
// Open the menu
await tester.tap(find.byType(DropdownMenu<TestMenu>));
await tester.pumpAndSettle();
expect(menuAnchor.controller!.isOpen, true);
// Simulate `TextInputAction.done` on textfield
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();
expect(menuAnchor.controller!.isOpen, false);
});
testWidgets('The onSelected gets called only when a selection is made', (WidgetTester tester) async {
int selectionCount = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment