Skip to content

Dropdown Menu layout respects menu items intrinsic sizes - #41120

Merged
HansMuller merged 2 commits into
flutter:masterfrom
HansMuller:dropdown_menu_vertical_layout
Sep 26, 2019
Merged

HansMuller merged 2 commits into
flutter:masterfrom
HansMuller:dropdown_menu_vertical_layout

Conversation

@HansMuller

@HansMuller HansMuller commented Sep 23, 2019 •

Copy link
Copy Markdown
Contributor

Fixes #40773.

Previously, dropdown menu items had a fixed height of 48 (kMinInteractiveDimension). Dropdown menu items now have a minimum size of 48 and no maximum size. When the menu appears, each item's vertical height will match its intrinsic height.

This test case demos dropdown menus with variable height items. It also uses the new selectedItemBuilder feature to render compact versions of the selected items within the dropdown button.

dropdowns

Previous Current
dropdown1_open_fail dropdown1_open
dropdown2_open_fail dropdown2_open

@fluttergithubbot fluttergithubbot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Sep 23, 2019
@HansMuller HansMuller added will affect goldens Changes to golden files and removed cla: yes labels Sep 23, 2019
@HansMuller
HansMuller force-pushed the dropdown_menu_vertical_layout branch from eb3453e to 04e4b1b Compare September 23, 2019 18:20
@shihaohong
shihaohong self-requested a review September 23, 2019 23:16
@HansMuller
HansMuller force-pushed the dropdown_menu_vertical_layout branch from 04e4b1b to 0583a87 Compare September 25, 2019 00:08

@shihaohong shihaohong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good! We should add docs to explain how to properly use this with selectedItemBuilder to get the desired effect multi-line effect, which could be a separate PR.

There's also an issue with the dropdown button itself not sizing properly with taller items, as you can see with this gist.

Here's a screenshot with the problem:
Screen Shot 2019-09-25 at 5 25 41 PM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it attempts to position it as such, and if it fails, adjusts accordingly.

Also, it might be clearer to directly describe that it aligns the vertical center of the selected item with the vertical center of the dropdown button.

Maybe something like:

// This widget enables _DropdownRoute to look up the sizes of
// each menu item. These sizes are used to compute the offset of the selected 
// item so that _DropdownRoutePage attempts to align the vertical center of the
// selected item lines up with the vertical center
// of the dropdown button.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I updated the comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we could remove the item property since it isn't used anywhere except in super.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used by _DropdownMenuState to look up the menu item's value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the previous indentation okay? Although, I don't think there's guidance on this in the style guide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that wasn't indented properly. Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these helper methods are really slick

@HansMuller
HansMuller force-pushed the dropdown_menu_vertical_layout branch from 0583a87 to 2ebfe83 Compare September 25, 2019 21:59

@gspencergoog gspencergoog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

import 'dart:math' as math;

import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "r" comes before "w", no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; reordered.

@HansMuller

Copy link
Copy Markdown
Contributor Author

@shihaohong per #41120 (review)
This is a separate problem with dropdown buttons: currently the underline is drawn on top of the selected item, 8 pixels from the bottom of the selected item. It's not noticeable with the default menu item size. I'm going to write a separate PR to fix the underline.

@shihaohong shihaohong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HansMuller
HansMuller merged commit e47a1dc into flutter:master Sep 26, 2019
@HansMuller
HansMuller deleted the dropdown_menu_vertical_layout branch September 26, 2019 14:18
HansMuller pushed a commit that referenced this pull request Sep 26, 2019
HansMuller added a commit that referenced this pull request Sep 27, 2019
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DropdownMenuItems are fixed height

5 participants