diff --git a/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart b/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart index 970a27c204d..0610c344ae4 100644 --- a/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart +++ b/examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart @@ -84,56 +84,64 @@ class _DropdownMenuExampleState extends State { children: [ Padding( padding: const EdgeInsets.symmetric(vertical: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - DropdownMenu( - 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(() { - selectedColor = color; - }); - }, - dropdownMenuEntries: ColorLabel.entries, - ), - const SizedBox(width: 24), - DropdownMenu( - controller: iconController, - enableFilter: true, - requestFocusOnTap: true, - leadingIcon: const Icon(Icons.search), - label: const Text('Icon'), - inputDecorationTheme: const InputDecorationTheme( - filled: true, - contentPadding: EdgeInsets.symmetric(vertical: 5.0), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + DropdownMenu( + initialSelection: ColorLabel.green, + controller: colorController, + // The default requestFocusOnTap value depends on the platform. + // On mobile, it defaults to false, and on desktop, it defaults to true. + // Setting this to true will trigger a focus request on the text field, and + // the virtual keyboard will appear afterward. + requestFocusOnTap: true, + label: const Text('Color'), + onSelected: (ColorLabel? color) { + setState(() { + selectedColor = color; + }); + }, + dropdownMenuEntries: ColorLabel.entries, ), - onSelected: (IconLabel? icon) { - setState(() { - selectedIcon = icon; - }); - }, - dropdownMenuEntries: IconLabel.entries, - ), - ], + const SizedBox(width: 24), + DropdownMenu( + controller: iconController, + enableFilter: true, + requestFocusOnTap: true, + leadingIcon: const Icon(Icons.search), + label: const Text('Icon'), + inputDecorationTheme: const InputDecorationTheme( + filled: true, + contentPadding: EdgeInsets.symmetric(vertical: 5.0), + ), + onSelected: (IconLabel? icon) { + setState(() { + selectedIcon = icon; + }); + }, + dropdownMenuEntries: IconLabel.entries, + ), + ], + ), ), ), if (selectedColor != null && selectedIcon != null) - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('You selected a ${selectedColor?.label} ${selectedIcon?.label}'), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 5), - child: Icon(selectedIcon?.icon, color: selectedColor?.color), - ), - ], + SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('You selected a ${selectedColor?.label} ${selectedIcon?.label}'), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 5), + child: Icon(selectedIcon?.icon, color: selectedColor?.color), + ), + ], + ), ) else const Text('Please select a color and an icon.'), diff --git a/examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart b/examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart index 324913b71cf..8e3ff6f5106 100644 --- a/examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart +++ b/examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart @@ -70,4 +70,41 @@ void main() { await tester.pumpAndSettle(); expect(FocusScope.of(tester.element(iconMenu)).hasFocus, isTrue); }); + + testWidgets('DropdownMenu on small screen', (WidgetTester tester) async { + await tester.pumpWidget(const example.DropdownMenuExample()); + + final Finder colorMenu = find.byType(DropdownMenu); + final Finder iconMenu = find.byType(DropdownMenu); + expect(colorMenu, findsOneWidget); + expect(iconMenu, findsOneWidget); + + Finder findMenuItem(String label) { + return find.widgetWithText(MenuItemButton, label).last; + } + + await tester.tap(colorMenu); + await tester.pumpAndSettle(); + final Finder menuBlue = findMenuItem('Blue'); + await tester.ensureVisible(menuBlue); + await tester.tap(menuBlue); + await tester.pumpAndSettle(); + + await tester.tap(iconMenu); + await tester.pumpAndSettle(); + final Finder menuSmile = findMenuItem('Smile'); + await tester.ensureVisible(menuSmile); + await tester.tap(menuSmile); + await tester.pumpAndSettle(); + + expect(find.text('You selected a Blue Smile'), findsOneWidget); + + // Resize the screen to small screen and make sure no overflowed error appears. + tester.binding.window.physicalSizeTestValue = const Size(200, 160); + tester.binding.window.devicePixelRatioTestValue = 1.0; + addTearDown(tester.binding.window.clearPhysicalSizeTestValue); + await tester.pump(); + + expect(tester.takeException(), isNull); + }); }