Skip to content

PopupMenuItem adds redundant padding when using ListItem #128553

Description

@Curstantine

Is there an existing issue for this?

Steps to reproduce

  1. Use a PopupMenuItem that uses a ListTile (Could be a custom one, or CheckedPopupMenuItem)

Expected results

For the item to follow 12dp horizontal padding as mentioned in the material spec without further configuration.

image

Actual results

The item is horizontally padded making the positioning out-of-spec. This could be resolved by removing the padding passed to the PopupMenuItem.

image

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
	runApp(const App());
}

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

	@override
	Widget build(context) {
		return MaterialApp(
			theme: ThemeData.light(useMaterial3: true),
			home: Scaffold(body: Center(child: PopupMenuButton(
				offset: const Offset(0, 56),
				itemBuilder: (context, ) => [
					const CheckedPopupMenuItem(
						checked: true,
						child: Text("checked"),
					),
					const PopupMenuItem(
						child: ListTile(
							leading: Icon(Icons.check_rounded),
							title: Text("checked"),
						),
					),
					const PopupMenuItem(
						padding: EdgeInsets.symmetric(horizontal: 0),
						child: ListTile(
							leading: Icon(Icons.logout),
							title: Text("Logout"),
						),
					)
				]
			)))
		);
	}
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.2, on Arch Linux 6.3.5-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.10.2 on channel stable at /home/<REDACTED>/Sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (2 weeks ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2)
    • Android SDK at /opt/android-sdk
    • Platform android-33, build-tools 34.0.0-rc2
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+7)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 15.0.7
    • cmake version 3.26.4
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (2 available)
    • <REDACTED> (mobile) • <REDACTED> • android-arm64 • Android 12 (API 31)
    • Linux (desktop)     • linux      • linux-x64     • Arch Linux 6.3.5-arch1-1

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

Activity

  1. Curstantine commented on Jun 9, 2023

    @Curstantine
    Author

    FWIW, I feel like PopupMenu take way too much horizontal space when ListTile is used. Likely because how ListTiles find its minimum intrinsic width. I forgot constraints exist.

    Oh, apparently label styles are wrong too.

  2. darshankawar commented on Jun 9, 2023

    @darshankawar
    Member

    @Curstantine
    Thanks for the report. From the code you shared, it seems you have explicitly added the padding to one of the ListTile which is causing the menu item to mis-align. If you remove the padding, it aligns properly with other menus.

    const PopupMenuItem(
                  //  padding: EdgeInsets.symmetric(horizontal: 0),
                    child: ListTile(
                      leading: Icon(Icons.logout),
                      title: Text("Logout"),
                    ),
                  )
    

    Is this correct interpretation of the issue or did I miss anything ?

    Oh, apparently label styles are wrong too.

    Can you also elaborate on this ?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 9, 2023
  4. Curstantine commented on Jun 9, 2023

    @Curstantine
    Author

    @Curstantine Thanks for the report. From the code you shared, it seems you have explicitly added the padding to one of the ListTile which is causing the menu item to mis-align. If you remove the padding, it aligns properly with other menus.

    It does align, yes, but in order for the MenuItem to be with spec, it only can have 12dp horizontal padding. (Which was why I removed the padding; for displaying)

    As an example, check:

    1. Material 3 Compose Sample App:
      image

    2. Reproducible sample added with the issue on dart pad:
      image


    Oh, apparently label styles are wrong too.
    Can you also elaborate on this ?

    The styles applied when using a ListTile on a Menu is the ListTile's default text style, instead of the text style mentioned in the Menu spec. Creating a distinctive size difference when compared to the Compose sample.

    1. Menu spec
      image

    2. ListTile spec
      image

    @darshankawar

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 9, 2023
  6. darshankawar commented on Jun 9, 2023

    @darshankawar
    Member

    Thanks for the feedback. When I verified earlier, the mis-alignment also occured without m3, so it seems not be specific to material 3. So curious to know what should be the expected behavior in this case ?

    The styles applied when using a ListTile on a Menu is the ListTile's default text style, instead of the text style mentioned in the Menu spec. Creating a distinctive size difference when compared to the Compose sample.

    I suggest you to file a new issue for this so that we can track it properly.

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 9, 2023
  8. Curstantine commented on Jun 9, 2023

    @Curstantine
    Author

    I think M2 implemetation is wrong too. The only difference I can see from M2 -> M3 is just the elevation and background colors.

    I genuinely think that using a ListTile just to add an icon to the menu is way too excessive, and more to the point, it adds properties to the MenuItem that aren't in-spec with M2/M3.

    As for the behavior,

    1. PopupMenuItem overrides the ListTileTheme so it can resolve the padding correctly.
    2. PopupMenuItem adds properties to add leading/trailing icons along with the label to refrain from depending on ListTile.
  9. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 9, 2023
  10. darshankawar commented on Jun 12, 2023

    @darshankawar
    Member

    @Curstantine
    According to PopupMenuItem documentation, if padding is null, horizontal padding defaults to 16.0 on both sides.

    https://api.flutter.dev/flutter/material/PopupMenuItem/padding.html

    So we probably don't need to explicitly add padding and can use the implementation without it as you have shared earlier, ie:

    const PopupMenuItem(
    	 child: ListTile(
    	leading: Icon(Icons.check_rounded),
    	title: Text("checked"),
    	),
    ),
    
  11. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 12, 2023
  12. Curstantine commented on Jun 12, 2023

    @Curstantine
    Author

    Ah, I might've missed that. Though again, as the documentation suggests, it's reccomended to use ListItem to add leadingIcon and trailingIcon, so the padding that defaults to 16dp on both sides should be null when the child is a ListItem. Else, setting up a ListItem becomes a hassle since you have to repetitively set the padding property of the PopupMenuItem.

  13. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 12, 2023
  14. darshankawar commented on Jun 12, 2023

    @darshankawar
    Member

    Thanks for the update. Have you looked at https://api.flutter.dev/flutter/material/ListTile/contentPadding.html to see if it helps in your case ?

  15. 27 remaining items

  16. moved this from ✅ Done to 🚧 In Progress in Material 3on Aug 13, 2023
  17. moved this from Done (PR merged) to In progress in Nevercodeon Aug 13, 2023
  18. removed
    r: fixedIssue is closed as already fixed in a newer version
    on Aug 14, 2023
  19. moved this from In progress to PR submitted in Nevercodeon Aug 15, 2023
  20. moved this from PR submitted to Done (PR merged) in Nevercodeon Aug 16, 2023
  21. moved this from 🚧 In Progress to ✅ Done in Material 3on Aug 16, 2023
  22. added a commit that references this issue on Aug 16, 2023
  23. added
    r: fixedIssue is closed as already fixed in a newer version
    on Aug 16, 2023
  24. github-actions commented on Aug 30, 2023

    @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.

  25. locked as resolved and limited conversation to collaborators on Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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 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