Improve DropdownMenu sample code for requestFocusOnTap on mobile platforms (#134867)
### Description This PR is to improve `DropdownMenu` sample code. By default, `requestFocusOnTap` is false on mobile platforms. When users run API sample code on mobile platforms, they can not edit the text field and think it is a bug. Although it is detailed at https://api.flutter.dev/flutter/material/DropdownMenu/requestFocusOnTap.html, users often do not pay attention to it. ### Related issue Fixes https://github.com/flutter/flutter/issues/127672
This commit is contained in:
@@ -52,4 +52,26 @@ void main() {
|
||||
|
||||
expect(find.text('You selected a Blue Smile'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('DropdownMenu has focus when tapping on the text field', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.DropdownMenuExample(),
|
||||
);
|
||||
|
||||
// Make sure the dropdown menus are there.
|
||||
final Finder colorMenu = find.byType(DropdownMenu<example.ColorLabel>);
|
||||
final Finder iconMenu = find.byType(DropdownMenu<example.IconLabel>);
|
||||
expect(colorMenu, findsOneWidget);
|
||||
expect(iconMenu, findsOneWidget);
|
||||
|
||||
// Tap on the color menu and make sure it is focused.
|
||||
await tester.tap(colorMenu);
|
||||
await tester.pumpAndSettle();
|
||||
expect(FocusScope.of(tester.element(colorMenu)).hasFocus, isTrue);
|
||||
|
||||
// Tap on the icon menu and make sure it is focused.
|
||||
await tester.tap(iconMenu);
|
||||
await tester.pumpAndSettle();
|
||||
expect(FocusScope.of(tester.element(iconMenu)).hasFocus, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user