dropdown_button2 icon indicating copy to clipboard operation
dropdown_button2 copied to clipboard

Adding vertical padding to MenuItemStyleData causes menuHeights wrong calculations and eventually menu disappears

Open pawlowskim opened this issue 2 years ago • 1 comments

I wanted to implement list with dividers, so I used customHeights for MenuItemStyleData. If I add vertical padding along with customHeights it causes odd behaviour. Like, each time dropdown is opened height for each row is reduced by the vertical padding. Eventually menu is not visible at all, because customHeights (in _DropdownRoute constructor) are all zeros.

On the other hand, when setting hardcoded height it works.

Example code could be taken from 3. DropdownButton2 with items of different heights like dividers, just add the vertical padding to the MenuItemStyleData

pawlowskim avatar Aug 23 '23 08:08 pawlowskim

void _handleTap() { final List<_MenuItem<T>> menuItems = [ for (int index = 0; index < widget.items!.length; index += 1) _MenuItem<T>( item: widget.items![index], onLayout: (Size size) { // If [_dropdownRoute] is null and onLayout is called, this means // that performLayout was called on a _DropdownRoute that has not // left the widget tree but is already on its way out. // // Since onLayout is used primarily to collect the desired heights // of each menu item before laying them out, not having the _DropdownRoute // collect each item's height to lay out is fine since the route is // already on its way out. if (_dropdownRoute == null) { return; } if (widget.customHeights == null ) { _dropdownRoute!.itemHeights[index] = size.height; } }, ), ]; dropdown_button2.dart内部重新给itemHeights赋值,导致bug

spring321 avatar Jun 10 '25 13:06 spring321