diff --git a/lib/src/widgets/toolbar_widget.dart b/lib/src/widgets/toolbar_widget.dart index 48e00fe2..f974bc5a 100644 --- a/lib/src/widgets/toolbar_widget.dart +++ b/lib/src/widgets/toolbar_widget.dart @@ -375,10 +375,13 @@ class ToolbarWidgetState extends State { itemHeight: widget.htmlToolbarOptions.dropdownItemHeight, focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), + menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -505,10 +508,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -582,10 +590,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -707,10 +720,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -1133,10 +1151,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -1350,10 +1373,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( @@ -1501,10 +1529,15 @@ class ToolbarWidgetState extends State { focusColor: widget.htmlToolbarOptions.dropdownFocusColor, dropdownColor: widget.htmlToolbarOptions.dropdownBackgroundColor, - menuDirection: widget.htmlToolbarOptions.dropdownMenuDirection ?? - (widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor ? DropdownMenuDirection.up : DropdownMenuDirection.down), - menuMaxHeight: widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? - MediaQuery.of(context).size.height / 3, + menuDirection: + widget.htmlToolbarOptions.dropdownMenuDirection ?? + (widget.htmlToolbarOptions.toolbarPosition == + ToolbarPosition.belowEditor + ? DropdownMenuDirection.up + : DropdownMenuDirection.down), + menuMaxHeight: + widget.htmlToolbarOptions.dropdownMenuMaxHeight ?? + MediaQuery.of(context).size.height / 3, style: widget.htmlToolbarOptions.textStyle, items: [ CustomDropdownMenuItem( diff --git a/lib/utils/options.dart b/lib/utils/options.dart index 09a1105a..4a93428b 100644 --- a/lib/utils/options.dart +++ b/lib/utils/options.dart @@ -324,6 +324,7 @@ class HtmlToolbarOptions { final double dropdownItemHeight; final Color? dropdownFocusColor; final Color? dropdownBackgroundColor; + /// Set the menu opening direction for the dropdown. Only useful when using /// [ToolbarPosition.custom] since the toolbar otherwise automatically /// determines the correct direction. diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 7d8c06e9..70d61972 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -9,7 +9,8 @@ import 'package:html_editor_enhanced/html_editor.dart'; import 'package:html_editor_enhanced/utils/shims/dart_ui.dart'; /// small function to always check if mounted before running setState() -void setState(bool mounted, void Function(Function ()) setState, void Function() fn) { +void setState( + bool mounted, void Function(Function()) setState, void Function() fn) { if (mounted) { setState.call(fn); } @@ -48,10 +49,12 @@ const Duration _kDropdownMenuDuration = Duration(milliseconds: 300); const double _kMenuItemHeight = kMinInteractiveDimension; const double _kDenseButtonHeight = 24.0; const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0); -const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsetsDirectional.only(start: 16.0, end: 4.0); +const EdgeInsetsGeometry _kAlignedButtonPadding = + EdgeInsetsDirectional.only(start: 16.0, end: 4.0); const EdgeInsets _kUnalignedButtonPadding = EdgeInsets.zero; const EdgeInsets _kAlignedMenuMargin = EdgeInsets.zero; -const EdgeInsetsGeometry _kUnalignedMenuMargin = EdgeInsetsDirectional.only(start: 16.0, end: 24.0); +const EdgeInsetsGeometry _kUnalignedMenuMargin = + EdgeInsetsDirectional.only(start: 16.0, end: 24.0); typedef DropdownButtonBuilder = List Function(BuildContext context); @@ -62,11 +65,11 @@ class _DropdownMenuPainter extends CustomPainter { this.selectedIndex, required this.resize, required this.getSelectedItemOffset, - }) : _painter = BoxDecoration( - color: color, - borderRadius: BorderRadius.circular(2.0), - boxShadow: kElevationToShadow[elevation], - ).createBoxPainter(), + }) : _painter = BoxDecoration( + color: color, + borderRadius: BorderRadius.circular(2.0), + boxShadow: kElevationToShadow[elevation], + ).createBoxPainter(), super(repaint: resize); final Color? color; @@ -80,26 +83,29 @@ class _DropdownMenuPainter extends CustomPainter { void paint(Canvas canvas, Size size) { final selectedItemOffset = getSelectedItemOffset(); final top = Tween( - begin: selectedItemOffset.clamp(0.0, max(size.height - _kMenuItemHeight, 0.0)), + begin: selectedItemOffset.clamp( + 0.0, max(size.height - _kMenuItemHeight, 0.0)), end: 0.0, ); final bottom = Tween( - begin: (top.begin! + _kMenuItemHeight).clamp(min(_kMenuItemHeight, size.height), size.height), + begin: (top.begin! + _kMenuItemHeight) + .clamp(min(_kMenuItemHeight, size.height), size.height), end: size.height, ); - final rect = Rect.fromLTRB(0.0, top.evaluate(resize), size.width, bottom.evaluate(resize)); + final rect = Rect.fromLTRB( + 0.0, top.evaluate(resize), size.width, bottom.evaluate(resize)); _painter.paint(canvas, rect.topLeft, ImageConfiguration(size: rect.size)); } @override bool shouldRepaint(_DropdownMenuPainter oldPainter) { - return oldPainter.color != color - || oldPainter.elevation != elevation - || oldPainter.selectedIndex != selectedIndex - || oldPainter.resize != resize; + return oldPainter.color != color || + oldPainter.elevation != elevation || + oldPainter.selectedIndex != selectedIndex || + oldPainter.resize != resize; } } @@ -120,10 +126,12 @@ class _DropdownMenuItemButton extends StatefulWidget { final int itemIndex; @override - _DropdownMenuItemButtonState createState() => _DropdownMenuItemButtonState(); + _DropdownMenuItemButtonState createState() => + _DropdownMenuItemButtonState(); } -class _DropdownMenuItemButtonState extends State<_DropdownMenuItemButton> { +class _DropdownMenuItemButtonState + extends State<_DropdownMenuItemButton> { void _handleFocusChange(bool focused) { final bool inTraditionalMode; switch (FocusManager.instance.highlightMode) { @@ -160,9 +168,12 @@ class _DropdownMenuItemButtonState extends State<_DropdownMenuItemButton> ); } - static final Map _webShortcuts ={ - LogicalKeySet(LogicalKeyboardKey.arrowDown): const DirectionalFocusIntent(TraversalDirection.down), - LogicalKeySet(LogicalKeyboardKey.arrowUp): const DirectionalFocusIntent(TraversalDirection.up), + static final Map _webShortcuts = + { + LogicalKeySet(LogicalKeyboardKey.arrowDown): + const DirectionalFocusIntent(TraversalDirection.down), + LogicalKeySet(LogicalKeyboardKey.arrowUp): + const DirectionalFocusIntent(TraversalDirection.up), }; @override @@ -170,11 +181,13 @@ class _DropdownMenuItemButtonState extends State<_DropdownMenuItemButton> final CurvedAnimation opacity; final unit = 0.5 / (widget.route.items.length + 1.5); if (widget.itemIndex == widget.route.selectedIndex) { - opacity = CurvedAnimation(parent: widget.route.animation!, curve: const Threshold(0.0)); + opacity = CurvedAnimation( + parent: widget.route.animation!, curve: const Threshold(0.0)); } else { final start = (0.5 + (widget.itemIndex + 1) * unit).clamp(0.0, 1.0); final end = (start + 1.5 * unit).clamp(0.0, 1.0); - opacity = CurvedAnimation(parent: widget.route.animation!, curve: Interval(start, end)); + opacity = CurvedAnimation( + parent: widget.route.animation!, curve: Interval(start, end)); } Widget child = FadeTransition( opacity: opacity, @@ -324,7 +337,8 @@ class _DropdownMenuRouteLayout extends SingleChildLayoutDelegate { @override Offset getPositionForChild(Size size, Size childSize) { - final menuLimits = route.getMenuLimits(buttonRect, size.height, route.selectedIndex); + final menuLimits = + route.getMenuLimits(buttonRect, size.height, route.selectedIndex); assert(() { final container = Offset.zero & size; @@ -350,7 +364,8 @@ class _DropdownMenuRouteLayout extends SingleChildLayoutDelegate { @override bool shouldRelayout(_DropdownMenuRouteLayout oldDelegate) { - return buttonRect != oldDelegate.buttonRect || textDirection != oldDelegate.textDirection; + return buttonRect != oldDelegate.buttonRect || + textDirection != oldDelegate.textDirection; } } @@ -362,8 +377,7 @@ class _DropdownRouteResult { @override bool operator ==(Object other) { - return other is _DropdownRouteResult - && other.result == result; + return other is _DropdownRouteResult && other.result == result; } @override @@ -392,7 +406,8 @@ class _DropdownRoute extends PopupRoute<_DropdownRouteResult> { this.dropdownColor, this.menuMaxHeight, required this.menuDirection, - }) : itemHeights = List.filled(items.length, itemHeight ?? kMinInteractiveDimension); + }) : itemHeights = List.filled( + items.length, itemHeight ?? kMinInteractiveDimension); final List<_MenuItem> items; final EdgeInsetsGeometry padding; @@ -422,7 +437,8 @@ class _DropdownRoute extends PopupRoute<_DropdownRouteResult> { final String? barrierLabel; @override - Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { + Widget buildPage(BuildContext context, Animation animation, + Animation secondaryAnimation) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { return _DropdownRoutePage( @@ -458,7 +474,8 @@ class _DropdownRoute extends PopupRoute<_DropdownRouteResult> { return offset; } - _MenuLimits getMenuLimits(Rect buttonRect, double availableHeight, int index) { + _MenuLimits getMenuLimits( + Rect buttonRect, double availableHeight, int index) { final maxMenuHeight = availableHeight - 2.0 * _kMenuItemHeight; final buttonTop = buttonRect.top; final buttonBottom = min(buttonRect.bottom, availableHeight); @@ -469,13 +486,16 @@ class _DropdownRoute extends PopupRoute<_DropdownRouteResult> { var preferredMenuHeight = kMaterialListPadding.vertical; if (items.isNotEmpty) { - preferredMenuHeight += itemHeights.reduce((double total, double height) => total + height); + preferredMenuHeight += + itemHeights.reduce((double total, double height) => total + height); } final menuHeight = min(maxMenuHeight, preferredMenuHeight); //the next two lines are the main change for reversed dropdown opening - var menuTop = menuDirection == DropdownMenuDirection.up ? buttonTop - min((menuMaxHeight ?? menuHeight), menuHeight) - : (buttonTop - selectedItemOffset) - (itemHeights[selectedIndex] - buttonRect.height) / 2.0; + var menuTop = menuDirection == DropdownMenuDirection.up + ? buttonTop - min((menuMaxHeight ?? menuHeight), menuHeight) + : (buttonTop - selectedItemOffset) - + (itemHeights[selectedIndex] - buttonRect.height) / 2.0; var menuBottom = menuTop + min((menuMaxHeight ?? menuHeight), menuHeight); if (menuTop < topLimit) { @@ -527,8 +547,10 @@ class _DropdownRoutePage extends StatelessWidget { Widget build(BuildContext context) { assert(debugCheckHasDirectionality(context)); if (route.scrollController == null) { - final menuLimits = route.getMenuLimits(buttonRect, constraints.maxHeight, selectedIndex); - route.scrollController = ScrollController(initialScrollOffset: menuLimits.scrollOffset); + final menuLimits = + route.getMenuLimits(buttonRect, constraints.maxHeight, selectedIndex); + route.scrollController = + ScrollController(initialScrollOffset: menuLimits.scrollOffset); } final textDirection = Directionality.maybeOf(context); @@ -578,7 +600,8 @@ class _MenuItem extends SingleChildRenderObjectWidget { } @override - void updateRenderObject(BuildContext context, covariant _RenderMenuItem renderObject) { + void updateRenderObject( + BuildContext context, covariant _RenderMenuItem renderObject) { renderObject.onLayout = onLayout; } } @@ -632,7 +655,9 @@ class CustomDropdownButtonHideUnderline extends InheritedWidget { }) : super(key: key, child: child); static bool at(BuildContext context) { - return context.dependOnInheritedWidgetOfExactType() != null; + return context.dependOnInheritedWidgetOfExactType< + CustomDropdownButtonHideUnderline>() != + null; } @override @@ -665,15 +690,20 @@ class CustomDropdownButton extends StatefulWidget { this.dropdownColor, this.menuMaxHeight, required this.menuDirection, - }) : assert(items == null || items.isEmpty || value == null || - items.where((CustomDropdownMenuItem item) { - return item.value == value; - }).length == 1, - "There should be exactly one item with [DropdownButton]'s value: " - '$value. \n' - 'Either zero or 2 or more [DropdownMenuItem]s were detected ' - 'with the same value', - ), assert(itemHeight == null || itemHeight >= kMinInteractiveDimension), + }) : assert( + items == null || + items.isEmpty || + value == null || + items.where((CustomDropdownMenuItem item) { + return item.value == value; + }).length == + 1, + "There should be exactly one item with [DropdownButton]'s value: " + '$value. \n' + 'Either zero or 2 or more [DropdownMenuItem]s were detected ' + 'with the same value', + ), + assert(itemHeight == null || itemHeight >= kMinInteractiveDimension), super(key: key); final DropdownMenuDirection menuDirection; @@ -704,7 +734,8 @@ class CustomDropdownButton extends StatefulWidget { _DropdownButtonState createState() => _DropdownButtonState(); } -class _DropdownButtonState extends State> with WidgetsBindingObserver { +class _DropdownButtonState extends State> + with WidgetsBindingObserver { int? _selectedIndex; _DropdownRoute? _dropdownRoute; Orientation? _lastOrientation; @@ -743,7 +774,8 @@ class _DropdownButtonState extends State> with Widget void dispose() { WidgetsBinding.instance!.removeObserver(this); _removeDropdownRoute(); - WidgetsBinding.instance!.focusManager.removeHighlightModeListener(_handleFocusHighlightModeChange); + WidgetsBinding.instance!.focusManager + .removeHighlightModeListener(_handleFocusHighlightModeChange); focusNode!.removeListener(_handleFocusChanged); _internalNode?.dispose(); super.dispose(); @@ -787,17 +819,22 @@ class _DropdownButtonState extends State> with Widget } void _updateSelectedIndex() { - if (widget.items == null - || widget.items!.isEmpty - || (widget.value == null && + if (widget.items == null || + widget.items!.isEmpty || + (widget.value == null && widget.items! - .where((CustomDropdownMenuItem item) => item.value == widget.value) + .where((CustomDropdownMenuItem item) => + item.value == widget.value) .isEmpty)) { _selectedIndex = null; return; } - assert(widget.items!.where((CustomDropdownMenuItem item) => item.value == widget.value).length == 1); + assert(widget.items! + .where( + (CustomDropdownMenuItem item) => item.value == widget.value) + .length == + 1); for (var itemIndex = 0; itemIndex < widget.items!.length; itemIndex++) { if (widget.items![itemIndex].value == widget.value) { _selectedIndex = itemIndex; @@ -806,7 +843,8 @@ class _DropdownButtonState extends State> with Widget } } - TextStyle? get _textStyle => widget.style ?? Theme.of(context).textTheme.subtitle1; + TextStyle? get _textStyle => + widget.style ?? Theme.of(context).textTheme.subtitle1; void _handleTap() { final textDirection = Directionality.maybeOf(context); @@ -831,7 +869,9 @@ class _DropdownButtonState extends State> with Widget final navigator = Navigator.of(context); assert(_dropdownRoute == null); final itemBox = context.findRenderObject()! as RenderBox; - final itemRect = itemBox.localToGlobal(Offset.zero, ancestor: navigator.context.findRenderObject()) & itemBox.size; + final itemRect = itemBox.localToGlobal(Offset.zero, + ancestor: navigator.context.findRenderObject()) & + itemBox.size; _dropdownRoute = _DropdownRoute( items: menuItems, @@ -839,7 +879,8 @@ class _DropdownButtonState extends State> with Widget padding: _kMenuItemPadding.resolve(textDirection), selectedIndex: _selectedIndex ?? 0, elevation: widget.elevation, - capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), + capturedThemes: + InheritedTheme.capture(from: context, to: navigator.context), style: _textStyle!, barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, itemHeight: widget.itemHeight, @@ -848,7 +889,9 @@ class _DropdownButtonState extends State> with Widget menuDirection: widget.menuDirection, ); - navigator.push(_dropdownRoute!).then((_DropdownRouteResult? newValue) { + navigator + .push(_dropdownRoute!) + .then((_DropdownRouteResult? newValue) { _removeDropdownRoute(); if (!mounted || newValue == null) { return; @@ -860,7 +903,8 @@ class _DropdownButtonState extends State> with Widget } double get _denseButtonHeight { - final fontSize = _textStyle!.fontSize ?? Theme.of(context).textTheme.subtitle1!.fontSize!; + final fontSize = _textStyle!.fontSize ?? + Theme.of(context).textTheme.subtitle1!.fontSize!; return max(fontSize, max(widget.iconSize, _kDenseButtonHeight)); } @@ -890,13 +934,18 @@ class _DropdownButtonState extends State> with Widget } } - bool get _enabled => widget.items != null && widget.items!.isNotEmpty && widget.onChanged != null; + bool get _enabled => + widget.items != null && + widget.items!.isNotEmpty && + widget.onChanged != null; Orientation _getOrientation(BuildContext context) { var result = MediaQuery.maybeOf(context)?.orientation; if (result == null) { final Size size = window.physicalSize; - result = size.width > size.height ? Orientation.landscape : Orientation.portrait; + result = size.width > size.height + ? Orientation.landscape + : Orientation.portrait; } return result; } @@ -927,7 +976,8 @@ class _DropdownButtonState extends State> with Widget int? hintIndex; if (widget.hint != null || (!_enabled && widget.disabledHint != null)) { - var displayedHint = _enabled ? widget.hint! : widget.disabledHint ?? widget.hint!; + var displayedHint = + _enabled ? widget.hint! : widget.disabledHint ?? widget.hint!; if (widget.selectedItemBuilder == null) { displayedHint = _DropdownMenuItemContainer(child: displayedHint); } @@ -953,24 +1003,30 @@ class _DropdownButtonState extends State> with Widget innerItemsWidget = IndexedStack( index: _selectedIndex ?? hintIndex, alignment: AlignmentDirectional.centerStart, - children: widget.isDense ? items : items.map((Widget item) { - return widget.itemHeight != null - ? SizedBox(height: widget.itemHeight, child: item) - : Column(mainAxisSize: MainAxisSize.min, children: [item]); - }).toList(), + children: widget.isDense + ? items + : items.map((Widget item) { + return widget.itemHeight != null + ? SizedBox(height: widget.itemHeight, child: item) + : Column( + mainAxisSize: MainAxisSize.min, + children: [item]); + }).toList(), ); } const defaultIcon = Icon(Icons.arrow_drop_down); Widget result = DefaultTextStyle( - style: _enabled ? _textStyle! : _textStyle!.copyWith(color: Theme.of(context).disabledColor), + style: _enabled + ? _textStyle! + : _textStyle!.copyWith(color: Theme.of(context).disabledColor), child: Container( decoration: _showHighlight ? BoxDecoration( - color: widget.focusColor ?? Theme.of(context).focusColor, - borderRadius: const BorderRadius.all(Radius.circular(4.0)), - ) + color: widget.focusColor ?? Theme.of(context).focusColor, + borderRadius: const BorderRadius.all(Radius.circular(4.0)), + ) : null, padding: padding.resolve(Directionality.of(context)), height: widget.isDense ? _denseButtonHeight : null, @@ -1003,17 +1059,18 @@ class _DropdownButtonState extends State> with Widget left: 0.0, right: 0.0, bottom: bottom, - child: widget.underline ?? Container( - height: 1.0, - decoration: const BoxDecoration( - border: Border( - bottom: BorderSide( - color: Color(0xFFBDBDBD), - width: 0.0, + child: widget.underline ?? + Container( + height: 1.0, + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide( + color: Color(0xFFBDBDBD), + width: 0.0, + ), + ), ), ), - ), - ), ), ], );