Skip to content

DropdownMenu can not be center aligned when using expandedInsets #155581

@av4625

Description

@av4625

Steps to reproduce

  1. Put a dropdown in a Center widget and put that inside an Expanded widget
  2. Use expandedInsets

Expected results

The dropdown should be centered

Actual results

The dropdown sticks to the top

Code sample

Code sample
Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    Expanded(
      child: Center(
        child: DropdownMenu<int>(
          inputDecorationTheme: const InputDecorationTheme(
            helperMaxLines: 5,
            border: OutlineInputBorder()
          ),
          expandedInsets: const EdgeInsets.symmetric(horizontal: 40),
          helperText: "Some long helper text.",
          initialSelection: 1,
          label: const Text("A number"),
          onSelected: (final int? num) {
          },
          dropdownMenuEntries:
            [1, 2, 3].map<DropdownMenuEntry<int>>(
              (final int num) {
                return DropdownMenuEntry<int>(
                  value: num,
                  label: "$num"
                );
              }
            ).toList(),
        ),
      ),
    ),
    Expanded(
      child: Center(
        child: DropdownMenu<double>(
          inputDecorationTheme: const InputDecorationTheme(
            helperMaxLines: 5,
            border: OutlineInputBorder()
          ),
          expandedInsets: const EdgeInsets.symmetric(horizontal: 40),
          helperText: "Long text.",
          initialSelection: 1.0,
          label: const Text("Another"),
          onSelected: (final double? num) {
          },
          dropdownMenuEntries:
            [1.0, 2.0, 3.0].map<DropdownMenuEntry<double>>(
              (final double num) {
                return DropdownMenuEntry<double>(
                  value: num,
                  label: "$num"
                );
              }
            ).toList(),
        ),
      ),
    ),
  ]
),

if (widget.expandedInsets case final EdgeInsetsGeometry padding) {
menuAnchor = Padding(
// Clamp the top and bottom padding to 0.
padding: padding.clamp(
EdgeInsets.zero,
const EdgeInsets.only(
left: double.infinity,
right: double.infinity,
).add(const EdgeInsetsDirectional.only(
end: double.infinity,
start: double.infinity,
),
),
),
child: Align(
alignment: AlignmentDirectional.topStart,
child: menuAnchor,
),
);
}

The second code block above seems to be the issue.

Screenshots or Video

Dropdowns stuck to the top image Remove `expandedInsets` and it comes down to the center but we lose the full width image

Logs

NA

Flutter Doctor output

Doctor output
% flutter doctor -v
[✓] Flutter (Channel stable, 3.24.1, on macOS 12.7.6 21H1320 darwin-x64, locale en-GB)
    • Flutter version 3.24.1 on channel stable at /Users/<user>/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (5 weeks ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/<user>/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/to/macos-android-setup for more details.

[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google
    Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.2)
    • Android Studio at /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.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.93.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.96.0

[✓] Connected device (2 available)
    • iPhone 14 Pro Max (mobile) • 1C6417FB-1C3E-4088-B3BD-8BD3E816ADD5 • ios        •
      com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64 • macOS 12.7.6 21H1320 darwin-x64

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

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.24Found to occur in 3.24found in release: 3.26Found to occur in 3.26frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: 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