flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.32k stars 27.53k forks source link

DropdownMenu Entries Not Positioned Correctly on Keyboard Appearance when `requestFocusOnTap` set to `true` #149037

Closed lew-kas closed 2 months ago

lew-kas commented 5 months ago

Steps to reproduce

  1. Use the provided code snippet from the Flutter examples below. The only difference from the actual example is the property requestFocusOnTap set to true
  2. Click into the DropdownMenu to enter a search term.
  3. Observe the behavior when the keyboard appears.

Expected results

The DropdownEntries should move upwards and be displayed right under the DropdownMenu when the keyboard appears.

Actual results

The DropdownEntries remain further down on the screen and do not follow the DropdownMenu as it moves upwards, causing a misalignment.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; /// Flutter code sample for the [DropdownMenuEntry] `labelWidget` property. enum ColorItem { blue('Blue', Colors.blue), pink('Pink', Colors.pink), green('Green', Colors.green), yellow('Yellow', Colors.yellow), grey('Grey', Colors.grey); const ColorItem(this.label, this.color); final String label; final Color color; } class DropdownMenuEntryLabelWidgetExample extends StatefulWidget { const DropdownMenuEntryLabelWidgetExample({super.key}); @override State createState() => _DropdownMenuEntryLabelWidgetExampleState(); } class _DropdownMenuEntryLabelWidgetExampleState extends State { late final TextEditingController controller; @override void initState() { super.initState(); controller = TextEditingController(); } @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { const String longText = 'is a color that sings of hope, A hue that shines like gold. It is the color of dreams, A shade that never grows old.'; return Scaffold( body: Center( child: DropdownMenu( width: 300, controller: controller, initialSelection: ColorItem.green, requestFocusOnTap: true, label: const Text('Color'), onSelected: (ColorItem? color) { print('Selected $color'); }, dropdownMenuEntries: ColorItem.values .map>((ColorItem item) { final String labelText = '${item.label} $longText\n'; return DropdownMenuEntry( value: item, label: labelText, labelWidget: Text( labelText, maxLines: 1, overflow: TextOverflow.ellipsis, ), ); }).toList(), ), ), ); } } class DropdownMenuEntryLabelWidgetExampleApp extends StatelessWidget { const DropdownMenuEntryLabelWidgetExampleApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: DropdownMenuEntryLabelWidgetExample(), ); } } void main() { runApp(const DropdownMenuEntryLabelWidgetExampleApp()); } ```

Screenshots or Video

Screenshots / Video demonstration [dropdownmenu.webm](https://github.com/flutter/flutter/assets/49316150/0e973408-407f-463a-b248-7cdd63faa76b)

Logs

Logs ```console ```

Flutter Doctor output

[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [Version 10.0.22631.3593], locale
de-DE) • Flutter version 3.22.1 on channel stable at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision a14f74ff3a (2 days ago), 2024-05-22 11:08:21 -0500 • Engine revision 55eae6864b • Dart version 3.4.1 • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4) • Android SDK at C:\Users\demo\AppData\Local\Android\Sdk • Platform android-34, build-tools 33.0.0-rc4 • ANDROID_SDK_ROOT = C:\Users\demo\AppData\Local\Android\Sdk • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.3) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.2.32526.322 • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2023.2) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)

[√] IntelliJ IDEA Ultimate Edition (version 2021.2) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.2 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart

[√] IntelliJ IDEA Ultimate Edition (version 2023.2) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2023.2 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.89.1) • VS Code at C:\Users\demo\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.88.0

[√] Connected device (4 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 31)
(emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3593] • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.210 • Edge (web) • edge • web-javascript • Microsoft Edge 125.0.2535.51

[√] Network resources • All expected network resources are available.

• No issues found!

darshankawar commented 5 months ago

Thanks for the report. I do see the same behavior using latest versions, wherein, tapping for the first time in the dropdown menu shows as below:

Screenshot 2024-05-24 at 6 23 12 PM

Whereas, all other subsequent taps in the dropdownmenu shows the menu entries properly:

Screenshot 2024-05-24 at 6 23 27 PM

If we set requestFocusOnTap to false, then the keyboard doesn't appear and we see below:

Screenshot 2024-05-24 at 6 24 43 PM

Maybe related : https://github.com/flutter/flutter/issues/147538

stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.22.0, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.22.0 on channel stable at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5dcb86f68f (5 days ago), 2024-05-09 07:39:20 -0500 • Engine revision f6344b75dc • Dart version 3.4.0 • DevTools version 2.34.3 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.22.0-45.0.pre.3, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.22.0-45.0.pre.3 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision fe0932f2c0 (4 hours ago), 2024-05-22 22:19:25 -0400 • Engine revision b8b82454e3 • Dart version 3.5.0 (build 3.5.0-178.0.dev) • DevTools version 2.36.0-dev.10 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/dhs/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 65.1.4 • Dart plugin version 213.7228 [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (3 available) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 15.3.1 19D52 • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.