Skip to content

MenuItemButton does not constrain its child #129439

@anlumo

Description

@anlumo

Is there an existing issue for this?

Steps to reproduce

Run the attached code and then make the window too narrow for the button.

Expected results

A menu item button with text that overflows with ellipsis.

Actual results

Layout error that the content of the button overflows its parent.

image

Code sample

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: 'MenuItemButton Demo',
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: Center(
        child: SizedBox(
          width: 300,
          child: MenuItemButton(
            child: const Text(
              'dsfljsadlkfjskfdljsaldkfjklsdsdaflajflkdjflsfjlaskdjfdadlkfksfljds',
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
              softWrap: false,
            ),
            onPressed: () {},
          ),
        ),
      ),
    );
  }
}

The problem is the two nested Rows in the _MenuItemLabel, according to the widget inspector:

image

Note how the outer Row has the right constraint, while the inner one is unconstrained.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.5, on Ubuntu 23.04 6.2.0-23-generic, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ✗ No Java Development Kit (JDK) found; You must have the environment variable JAVA_HOME set and the java binary in your
      PATH. You can download the JDK from https://www.oracle.com/technetwork/java/javase/downloads/.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.79.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.found in release: 3.10Found to occur in 3.10found in release: 3.12Found to occur in 3.12frameworkflutter/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 teamworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions