diff --git a/packages/dropdown_button2/lib/src/dropdown_button2.dart b/packages/dropdown_button2/lib/src/dropdown_button2.dart index 1fa876d..633d829 100644 --- a/packages/dropdown_button2/lib/src/dropdown_button2.dart +++ b/packages/dropdown_button2/lib/src/dropdown_button2.dart @@ -802,23 +802,28 @@ class _DropdownButton2State extends State> with WidgetsBin // which enhances the performance when dealing with big items list. // Note: Both buttonHeight & buttonWidth must be specified to avoid changing // button's size when selecting different items, which is a bad UX. - return buttonHeight != null && _buttonStyle?.width != null + return buttonHeight != null ? Align( alignment: widget.alignment, child: item, ) - : IndexedStack( - index: _selectedIndex ?? hintIndex, - alignment: widget.alignment, - children: buttonHeight != null - ? buttonItems - : buttonItems.map((item) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [item], - ); - }).toList(), - ); + : _buttonStyle?.width != null + ? IndexedStack( + index: _selectedIndex ?? hintIndex, + alignment: widget.alignment, + children: buttonHeight != null + ? buttonItems + : buttonItems.map((item) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [item], + ); + }).toList(), + ) + : SizedBox( + height: buttonHeight, + child: item, + ); }, ); @@ -849,7 +854,10 @@ class _DropdownButton2State extends State> with WidgetsBin mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisSize: MainAxisSize.min, children: [ - if (widget.isExpanded) Expanded(child: innerItemsWidget) else innerItemsWidget, + if (widget.isExpanded && _buttonStyle?.width != null) + Expanded(child: innerItemsWidget) + else + innerItemsWidget, IconTheme( data: IconThemeData( color: _iconColor, diff --git a/packages/dropdown_button2/lib/src/dropdown_route.dart b/packages/dropdown_button2/lib/src/dropdown_route.dart index dc26d79..ce10c5b 100644 --- a/packages/dropdown_button2/lib/src/dropdown_route.dart +++ b/packages/dropdown_button2/lib/src/dropdown_route.dart @@ -409,29 +409,29 @@ class _DropdownMenuRouteLayout extends SingleChildLayoutDelegate { DropdownDirection.textDirection => switch (textDirection!) { TextDirection.rtl => clampDouble( buttonRect.right - childSize.width + offset.dx, - 0.0, - size.width - childSize.width, + route.dropdownStyle.margin?.right ?? 0.00, + size.width - childSize.width - (route.dropdownStyle.margin?.left ?? 0), ), TextDirection.ltr => clampDouble( buttonRect.left + offset.dx, - 0.0, - size.width - childSize.width, + route.dropdownStyle.margin?.left ?? 0.00, + size.width - childSize.width - (route.dropdownStyle.margin?.right ?? 0), ), }, DropdownDirection.right => clampDouble( buttonRect.left + offset.dx, - 0.0, - size.width - childSize.width, + route.dropdownStyle.margin?.right ?? 0.00, + size.width - childSize.width - (route.dropdownStyle.margin?.left ?? 0), ), DropdownDirection.left => clampDouble( buttonRect.right - childSize.width + offset.dx, - 0.0, - size.width - childSize.width, + route.dropdownStyle.margin?.right ?? 0.00, + size.width - childSize.width - (route.dropdownStyle.margin?.right ?? 0), ), DropdownDirection.center => clampDouble( (size.width - childSize.width) / 2 + offset.dx, - 0.0, - size.width - childSize.width, + route.dropdownStyle.margin?.left ?? 0.00, + size.width - childSize.width - (route.dropdownStyle.margin?.right ?? 0), ), }; diff --git a/packages/dropdown_button2/lib/src/dropdown_style_data.dart b/packages/dropdown_button2/lib/src/dropdown_style_data.dart index 7c9d6e2..b0986cc 100644 --- a/packages/dropdown_button2/lib/src/dropdown_style_data.dart +++ b/packages/dropdown_button2/lib/src/dropdown_style_data.dart @@ -4,6 +4,7 @@ part of 'dropdown_button2.dart'; class DropdownStyleData { /// Creates a DropdownStyleData. const DropdownStyleData({ + this.margin, this.maxHeight, this.width, this.padding, @@ -21,6 +22,9 @@ class DropdownStyleData { this.dropdownBuilder, }); + /// The outer margin of the dropdown menu + final EdgeInsets? margin; + /// The maximum height of the dropdown menu /// /// The maximum height of the menu must be at least one row shorter than @@ -112,6 +116,7 @@ class DropdownStyleData { /// Create a clone of the current [DropdownStyleData] but with the provided /// parameters overridden. DropdownStyleData copyWith({ + EdgeInsets? margin, double? maxHeight, double? width, EdgeInsetsGeometry? padding, @@ -129,6 +134,7 @@ class DropdownStyleData { DropdownBuilder? dropdownBuilder, }) { return DropdownStyleData( + margin: margin ?? this.margin, maxHeight: maxHeight ?? this.maxHeight, width: width ?? this.width, padding: padding ?? this.padding,