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:
huycozy
2023-09-18 15:33:14 +07:00
committed by GitHub
parent b03f5337df
commit c2b1e483dd
2 changed files with 28 additions and 0 deletions

View File

@@ -74,6 +74,11 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
DropdownMenu<ColorLabel>(
initialSelection: ColorLabel.green,
controller: colorController,
// requestFocusOnTap is enabled/disabled by platforms when it is null.
// On mobile platforms, this is false by default. Setting this to true will
// trigger focus request on the text field and virtual keyboard will appear
// afterward. On desktop platforms however, this defaults to true.
requestFocusOnTap: true,
label: const Text('Color'),
onSelected: (ColorLabel? color) {
setState(() {
@@ -97,6 +102,7 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
DropdownMenu<IconLabel>(
controller: iconController,
enableFilter: true,
requestFocusOnTap: true,
leadingIcon: const Icon(Icons.search),
label: const Text('Icon'),
inputDecorationTheme: const InputDecorationTheme(