[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].*
This commit is contained in:
parent
43afac1e29
commit
c65cab8fa3
@ -612,9 +612,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
|||||||
if (!widget.enableSearch) {
|
if (!widget.enableSearch) {
|
||||||
currentHighlight = null;
|
currentHighlight = null;
|
||||||
}
|
}
|
||||||
if (_textEditingController.text.isNotEmpty) {
|
controller.close();
|
||||||
controller.close();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onTap: () {
|
onTap: () {
|
||||||
handlePressed(controller);
|
handlePressed(controller);
|
||||||
|
@ -1050,6 +1050,34 @@ void main() {
|
|||||||
expect(controller.text, 'New Item');
|
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 {
|
testWidgets('The onSelected gets called only when a selection is made', (WidgetTester tester) async {
|
||||||
int selectionCount = 0;
|
int selectionCount = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user