Skip to content

DropdownMenu does not correctly handle incoming maxWidth and minHeight constraints #147076

Closed

Description

@Hixie

Consider the following demo:

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Container(
        alignment: Alignment.center,
        color: Colors.amber,
        child: SizedBox(
          height: 100.0,
          width: 100.0,
          child: Card(
            child: DropdownMenu(
              dropdownMenuEntries: [
                DropdownMenuEntry(
                  value: '',
                  label: 'This is a very long label',
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

It should display a 100x100 widget, or at least a widget not wider than 100 pixels, whose menu appears below it.

Instead it displays a widget that is wider than the maxWidth (painting outside of its allowed bounds), and the menu renders below the minHeight, not under the actual widget:

The width aspect of this in particular is quite serious as it makes it impossible to use this widget with user-controlled text without risking overflow. You can't even set a labelWidget that makes the text wrap or truncate, because the labels don't receive the constraints.

Activity

  1. danagbemava-nc commented on Apr 22, 2024

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    flutter doctor -v
    [!] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.19.6 on channel stable at /Users/nexus/dev/sdks/flutter
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 54e66469a9 (4 days ago), 2024-04-17 13:08:03 -0700
        • Engine revision c4cd48e186
        • Dart version 3.3.4
        • DevTools version 2.31.1
        • 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 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • 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.7+0-17.0.7b1000.6-10550314)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.88.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.86.0
    
    [✓] Connected device (4 available)
        • Nexus (mobile)       • 00008020-001875E83A38002E • ios            • iOS 17.4.1 21E236
        • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios            • iOS 17.4.1 21E236
        • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
        • Chrome (web)         • chrome                    • web-javascript • Google Chrome 124.0.6367.60
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel master, 3.22.0-14.0.pre.67, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.22.0-14.0.pre.67 on channel master at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 1a905d508d (20 hours ago), 2024-04-21 06:44:23 -0400
        • Engine revision 75ca2195c9
        • Dart version 3.5.0 (build 3.5.0-83.0.dev)
        • DevTools version 2.35.0-dev.8
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • 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.7+0-17.0.7b1000.6-10550314)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.88.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.86.0
    
    [✓] Connected device (5 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.4.1 21E236
        • Dean’s iPad (mobile)            • 00008103-000825C811E3401E • ios            • iOS 17.4.1 21E236
        • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.4.1 23E224 darwin-arm64
        • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 124.0.6367.60
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Apr 22, 2024
  3. PurplePolyhedron commented on Apr 22, 2024

    @PurplePolyhedron
    Contributor

    For the width overflow, it seems to be cause by the textfield not constraint by the widget constraint here link
    I made a draft fix, but haven't figure out the test yet ffa54dd

  4. bleroux commented on Apr 23, 2024

    @bleroux
    Contributor

    @PurplePolyhedron
    Great! Looks like you found one root cause of this issue which seems to be getMaxIntrinsicWidth being called with width as a parameter instead of height and similar problem with getMaxIntrinsicHeight.
    Are you interested in filing a PR?
    I assigned you for the moment and I can help to review/write test.

  5. PurplePolyhedron commented on Apr 23, 2024

    @PurplePolyhedron
    Contributor

    @PurplePolyhedron Great! Looks like you found one root cause of this issue which seems to be getMaxIntrinsicWidth being called with width as a parameter instead of height and similar problem with getMaxIntrinsicHeight. Are you interested in filing a PR? I assigned you for the moment and I can help to review/write test.

    Thanks, I will try to file a PR soon.

  6. PurplePolyhedron commented on Apr 23, 2024

    @PurplePolyhedron
    Contributor

    @bleroux I've filed an PR and written some tests. Let me know if it need more tests or any changes.

  7. 2 remaining items

  8. added a commit that references this issue on May 1, 2024
  9. flutter-triage-bot commented on Aug 28, 2024

    @flutter-triage-bot

    This issue is assigned to @PurplePolyhedron but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  10. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Aug 28, 2024
  11. moved this from PR submitted to Done (PR merged) in Nevercodeon Dec 3, 2024
  12. added
    r: fixedIssue is closed as already fixed in a newer version
    on Dec 4, 2024
  13. github-actions commented on Dec 18, 2024

    @github-actions

    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.

  14. locked as resolved and limited conversation to collaborators on Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions