@@ -25,13 +25,11 @@ const Duration _kDropdownMenuDuration = Duration(milliseconds: 300);
2525const double _kMenuItemHeight = kMinInteractiveDimension;
2626const double _kDenseButtonHeight = 24.0 ;
2727const EdgeInsets _kMenuItemPadding = EdgeInsets .symmetric (horizontal: 16.0 );
28- const EdgeInsetsGeometry _kAlignedButtonPadding =
29- EdgeInsetsDirectional .only (start: 16.0 , end: 4.0 );
28+ const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsetsDirectional .only (start: 16.0 , end: 4.0 );
3029const EdgeInsets _kUnalignedButtonPadding = EdgeInsets .zero;
3130
3231/// A builder to customize the selected menu item.
33- typedef SelectedMenuItemBuilder = Widget Function (
34- BuildContext context, Widget child);
32+ typedef SelectedMenuItemBuilder = Widget Function (BuildContext context, Widget child);
3533
3634/// A builder to customize the dropdown menu.
3735typedef DropdownBuilder = Widget Function (BuildContext context, Widget child);
@@ -40,8 +38,7 @@ typedef DropdownBuilder = Widget Function(BuildContext context, Widget child);
4038typedef OnMenuStateChangeFn = void Function (bool isOpen);
4139
4240/// Signature for the callback for the match function used for searchable dropdowns.
43- typedef SearchMatchFn <T > = bool Function (
44- DropdownItem <T > item, String searchValue);
41+ typedef SearchMatchFn <T > = bool Function (DropdownItem <T > item, String searchValue);
4542
4643/// A Material Design button for selecting from a list of items.
4744///
@@ -389,8 +386,7 @@ class DropdownButton2<T> extends StatefulWidget {
389386 State <DropdownButton2 <T >> createState () => _DropdownButton2State <T >();
390387}
391388
392- class _DropdownButton2State <T > extends State <DropdownButton2 <T >>
393- with WidgetsBindingObserver {
389+ class _DropdownButton2State <T > extends State <DropdownButton2 <T >> with WidgetsBindingObserver {
394390 int ? _selectedIndex;
395391 _DropdownRoute <T >? _dropdownRoute;
396392 Orientation ? _lastOrientation;
@@ -453,8 +449,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
453449 WidgetsBinding .instance.removeObserver (this );
454450 widget.valueListenable? .removeListener (_updateSelectedIndex);
455451 widget.multiValueListenable? .removeListener (_updateSelectedIndex);
456- widget.openDropdownListenable
457- ? .removeListener (_programmaticallyOpenDropdown);
452+ widget.openDropdownListenable? .removeListener (_programmaticallyOpenDropdown);
458453 _removeDropdownRoute ();
459454 _focusNode.removeListener (_handleFocusChanged);
460455 _internalNode? .dispose ();
@@ -510,8 +505,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
510505 }
511506
512507 if (widget.openDropdownListenable != oldWidget.openDropdownListenable) {
513- oldWidget.openDropdownListenable
514- ? .removeListener (_programmaticallyOpenDropdown);
508+ oldWidget.openDropdownListenable? .removeListener (_programmaticallyOpenDropdown);
515509 widget.openDropdownListenable? .addListener (_programmaticallyOpenDropdown);
516510 }
517511 }
@@ -521,8 +515,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
521515 widget.items! .isEmpty ||
522516 (_currentValue == null &&
523517 widget.items!
524- .where ((DropdownItem <T > item) =>
525- item.enabled && item.value == _currentValue)
518+ .where ((DropdownItem <T > item) => item.enabled && item.value == _currentValue)
526519 .isEmpty)) {
527520 _selectedIndex = null ;
528521 return ;
@@ -551,23 +544,19 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
551544 _buttonRect.value = _getButtonRect ();
552545 }
553546
554- TextStyle ? get _textStyle =>
555- widget.style ?? Theme .of (context).textTheme.titleMedium;
547+ TextStyle ? get _textStyle => widget.style ?? Theme .of (context).textTheme.titleMedium;
556548
557549 Rect _getButtonRect () {
558550 // InputDecorator is a parent of _buttonRect (to avoid the dropdown menu opening under the button's error/helper),
559551 // so we need to consider its padding in additional to _buttonRect.
560- final EdgeInsets contentPadding =
561- _getInputDecorationPadding () ?? EdgeInsets .zero;
552+ final EdgeInsets contentPadding = _getInputDecorationPadding () ?? EdgeInsets .zero;
562553 final NavigatorState navigator = Navigator .of (context,
563- rootNavigator:
564- _dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator);
554+ rootNavigator: _dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator);
565555
566- final RenderBox itemBox =
567- _buttonRectKey.currentContext! .findRenderObject ()! as RenderBox ;
568- final Rect itemRect = itemBox.localToGlobal (Offset .zero,
569- ancestor: navigator.context.findRenderObject ()) &
570- itemBox.size;
556+ final RenderBox itemBox = _buttonRectKey.currentContext! .findRenderObject ()! as RenderBox ;
557+ final Rect itemRect =
558+ itemBox.localToGlobal (Offset .zero, ancestor: navigator.context.findRenderObject ()) &
559+ itemBox.size;
571560
572561 return contentPadding.inflateRect (itemRect);
573562 }
@@ -576,8 +565,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
576565 // Return the contentPadding only if inputDecoration is defined.
577566 if (widget._inputDecoration case final decoration? ) {
578567 final TextDirection ? textDirection = Directionality .maybeOf (context);
579- return (decoration.contentPadding ??
580- Theme .of (context).inputDecorationTheme.contentPadding)
568+ return (decoration.contentPadding ?? Theme .of (context).inputDecorationTheme.contentPadding)
581569 ? .resolve (textDirection);
582570 } else {
583571 return null ;
@@ -587,10 +575,9 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
587575 EdgeInsetsGeometry _buttonAdditionalHPadding () {
588576 final TextDirection ? textDirection = Directionality .maybeOf (context);
589577
590- final menuItemPadding =
591- _menuItemStyle.padding? .resolve (textDirection) ?? _kMenuItemPadding;
592- final removeItemHPadding = _menuItemStyle.useDecorationHorizontalPadding &&
593- _getInputDecorationPadding () != null ;
578+ final menuItemPadding = _menuItemStyle.padding? .resolve (textDirection) ?? _kMenuItemPadding;
579+ final removeItemHPadding =
580+ _menuItemStyle.useDecorationHorizontalPadding && _getInputDecorationPadding () != null ;
594581 final effectiveMenuItemPadding = menuItemPadding.copyWith (
595582 left: removeItemHPadding ? 0 : null ,
596583 right: removeItemHPadding ? 0 : null ,
@@ -605,8 +592,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
605592
606593 void _handleTap () {
607594 final NavigatorState navigator = Navigator .of (context,
608- rootNavigator:
609- _dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator);
595+ rootNavigator: _dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator);
610596
611597 final items = widget.items! ;
612598 final separator = widget.dropdownSeparator;
@@ -619,13 +605,12 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
619605 selectedIndex: _selectedIndex ?? 0 ,
620606 isNoSelectedItem: _selectedIndex == null ,
621607 onChanged: widget.onChanged,
622- capturedThemes:
623- InheritedTheme .capture (from: context, to: navigator.context),
608+ capturedThemes: InheritedTheme .capture (from: context, to: navigator.context),
624609 style: _textStyle! ,
625610 barrierDismissible: widget.barrierDismissible,
626611 barrierColor: widget.barrierColor,
627- barrierLabel: widget.barrierLabel ??
628- MaterialLocalizations .of (context).modalBarrierDismissLabel,
612+ barrierLabel:
613+ widget.barrierLabel ?? MaterialLocalizations .of (context).modalBarrierDismissLabel,
629614 barrierCoversButton: widget.barrierCoversButton,
630615 parentFocusNode: _focusNode,
631616 enableFeedback: widget.enableFeedback ?? true ,
@@ -643,9 +628,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
643628 WidgetsBinding .instance.addPostFrameCallback ((_) {
644629 _dropdownRoute? ._childNode.requestFocus ();
645630 });
646- navigator
647- .push (_dropdownRoute! )
648- .then <void >((_DropdownRouteResult <T >? newValue) {
631+ navigator.push (_dropdownRoute! ).then <void >((_DropdownRouteResult <T >? newValue) {
649632 _removeDropdownRoute ();
650633 _isMenuOpen.value = false ;
651634 widget.onMenuStateChange? .call (false );
@@ -659,12 +642,10 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
659642 // Similarly, we don't reduce the height of the button so much that its icon
660643 // would be clipped.
661644 double get _denseButtonHeight {
662- final double fontSize = _textStyle! .fontSize ??
663- Theme .of (context).textTheme.titleMedium! .fontSize! ;
664- final double scaledFontSize =
665- MediaQuery .textScalerOf (context).scale (fontSize);
666- return math.max (
667- scaledFontSize, math.max (_iconStyle.iconSize, _kDenseButtonHeight));
645+ final double fontSize =
646+ _textStyle! .fontSize ?? Theme .of (context).textTheme.titleMedium! .fontSize! ;
647+ final double scaledFontSize = MediaQuery .textScalerOf (context).scale (fontSize);
648+ return math.max (scaledFontSize, math.max (_iconStyle.iconSize, _kDenseButtonHeight));
668649 }
669650
670651 Color get _iconColor {
@@ -685,27 +666,22 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
685666 }
686667 }
687668
688- bool get _enabled =>
689- widget.items != null &&
690- widget.items! .isNotEmpty &&
691- widget.onChanged != null ;
669+ bool get _enabled => widget.items != null && widget.items! .isNotEmpty && widget.onChanged != null ;
692670
693671 Orientation _getOrientation (BuildContext context) {
694672 Orientation ? result = MediaQuery .maybeOrientationOf (context);
695673 if (result == null ) {
696674 // If there's no MediaQuery, then use the current FlutterView to determine
697675 // orientation.
698676 final Size size = View .of (context).physicalSize;
699- result = size.width > size.height
700- ? Orientation .landscape
701- : Orientation .portrait;
677+ result = size.width > size.height ? Orientation .landscape : Orientation .portrait;
702678 }
703679 return result;
704680 }
705681
706682 BorderRadius ? _getButtonBorderRadius (BuildContext context) {
707- final buttonRadius = _buttonStyle ? .decoration ? .borderRadius ??
708- _buttonStyle? .foregroundDecoration? .borderRadius;
683+ final buttonRadius =
684+ _buttonStyle? .decoration ? .borderRadius ?? _buttonStyle ? . foregroundDecoration? .borderRadius;
709685 if (buttonRadius != null ) {
710686 return buttonRadius.resolve (Directionality .maybeOf (context));
711687 }
@@ -735,8 +711,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
735711
736712 int ? hintIndex;
737713 if (widget.hint != null || (! _enabled && widget.disabledHint != null )) {
738- final Widget displayedHint =
739- _enabled ? widget.hint! : widget.disabledHint ?? widget.hint! ;
714+ final Widget displayedHint = _enabled ? widget.hint! : widget.disabledHint ?? widget.hint! ;
740715
741716 hintIndex = buttonItems.length;
742717 buttonItems.add (DefaultTextStyle (
@@ -747,19 +722,16 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
747722 ));
748723 }
749724
750- final EdgeInsetsGeometry padding = ButtonTheme .of (context).alignedDropdown
751- ? _kAlignedButtonPadding
752- : _kUnalignedButtonPadding;
725+ final EdgeInsetsGeometry padding =
726+ ButtonTheme .of (context).alignedDropdown ? _kAlignedButtonPadding : _kUnalignedButtonPadding;
753727
754- final buttonHeight =
755- _buttonStyle? .height ?? (widget.isDense ? _denseButtonHeight : null );
728+ final buttonHeight = _buttonStyle? .height ?? (widget.isDense ? _denseButtonHeight : null );
756729
757730 final Widget innerItemsWidget = buttonItems.isEmpty
758731 ? const SizedBox .shrink ()
759732 : ValueListenableBuilder (
760- valueListenable: widget.valueListenable ??
761- widget.multiValueListenable ??
762- ValueNotifier (null ),
733+ valueListenable:
734+ widget.valueListenable ?? widget.multiValueListenable ?? ValueNotifier (null ),
763735 builder: (context, _, __) {
764736 _uniqueValueAssert (
765737 widget.items,
@@ -796,9 +768,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
796768 );
797769
798770 Widget result = DefaultTextStyle (
799- style: _enabled
800- ? _textStyle!
801- : _textStyle! .copyWith (color: Theme .of (context).disabledColor),
771+ style: _enabled ? _textStyle! : _textStyle! .copyWith (color: Theme .of (context).disabledColor),
802772 child: widget.customButton ??
803773 _ConditionalDecoratedBox (
804774 decoration: _buttonStyle? .decoration? .copyWith (
@@ -824,10 +794,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
824794 mainAxisAlignment: MainAxisAlignment .spaceBetween,
825795 mainAxisSize: MainAxisSize .min,
826796 children: < Widget > [
827- if (widget.isExpanded)
828- Expanded (child: innerItemsWidget)
829- else
830- innerItemsWidget,
797+ if (widget.isExpanded) Expanded (child: innerItemsWidget) else innerItemsWidget,
831798 IconTheme (
832799 data: IconThemeData (
833800 color: _iconColor,
@@ -876,8 +843,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
876843 );
877844 }
878845
879- final MouseCursor effectiveMouseCursor =
880- WidgetStateProperty .resolveAs <MouseCursor >(
846+ final MouseCursor effectiveMouseCursor = WidgetStateProperty .resolveAs <MouseCursor >(
881847 WidgetStateMouseCursor .clickable,
882848 < WidgetState > {
883849 if (! _enabled) WidgetState .disabled,
@@ -900,8 +866,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
900866 final focusColor = effectiveDecoration.focusColor;
901867 // For compatibility, override the fill color when focusColor is set.
902868 if (focusColor != null ) {
903- effectiveDecoration =
904- effectiveDecoration.copyWith (fillColor: focusColor);
869+ effectiveDecoration = effectiveDecoration.copyWith (fillColor: focusColor);
905870 }
906871 }
907872 result = Focus (
@@ -926,8 +891,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
926891 cursor: effectiveMouseCursor,
927892 child: GestureDetector (
928893 onTap: _enabled && ! widget.openWithLongPress ? _handleTap : null ,
929- onLongPress:
930- _enabled && widget.openWithLongPress ? _handleTap : null ,
894+ onLongPress: _enabled && widget.openWithLongPress ? _handleTap : null ,
931895 behavior: HitTestBehavior .opaque,
932896 child: InputDecorator (
933897 decoration: effectiveDecoration,
@@ -954,8 +918,8 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
954918 );
955919 }
956920
957- final bool childHasButtonSemantic = hintIndex != null ||
958- (_selectedIndex != null && widget.selectedItemBuilder == null );
921+ final bool childHasButtonSemantic =
922+ hintIndex != null || (_selectedIndex != null && widget.selectedItemBuilder == null );
959923 return Semantics (
960924 button: ! childHasButtonSemantic,
961925 child: Actions (
@@ -1033,19 +997,14 @@ class DropdownButtonFormField2<T> extends FormField<T> {
1033997 builder: (FormFieldState <T > field) {
1034998 final _DropdownButtonFormFieldState <T > state =
1035999 field as _DropdownButtonFormFieldState <T >;
1036- final InputDecoration decorationArg =
1037- decoration ?? const InputDecoration ();
1038- final InputDecoration effectiveDecoration =
1039- decorationArg.applyDefaults (
1000+ final InputDecoration decorationArg = decoration ?? const InputDecoration ();
1001+ final InputDecoration effectiveDecoration = decorationArg.applyDefaults (
10401002 Theme .of (field.context).inputDecorationTheme,
10411003 );
10421004
10431005 final bool showSelectedItem = items != null &&
1044- items
1045- .where ((DropdownItem <T > item) => item.value == state.value)
1046- .isNotEmpty;
1047- final bool isDropdownEnabled =
1048- onChanged != null && items != null && items.isNotEmpty;
1006+ items.where ((DropdownItem <T > item) => item.value == state.value).isNotEmpty;
1007+ final bool isDropdownEnabled = onChanged != null && items != null && items.isNotEmpty;
10491008 // If decoration hintText is provided, use it as the default value for both hint and disabledHint.
10501009 final Widget ? decorationHint = effectiveDecoration.hintText != null
10511010 ? Text (
@@ -1060,8 +1019,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10601019 final bool isHintOrDisabledHintAvailable = isDropdownEnabled
10611020 ? effectiveHint != null
10621021 : effectiveHint != null || effectiveDisabledHint != null ;
1063- final bool isEmpty =
1064- ! showSelectedItem && ! isHintOrDisabledHintAvailable;
1022+ final bool isEmpty = ! showSelectedItem && ! isHintOrDisabledHintAvailable;
10651023
10661024 // An unFocusable Focus widget so that this widget can detect if its
10671025 // descendants have focus or not.
@@ -1123,8 +1081,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
11231081}
11241082
11251083class _DropdownButtonFormFieldState <T > extends FormFieldState <T > {
1126- DropdownButtonFormField <T > get _dropdownButtonFormField =>
1127- widget as DropdownButtonFormField <T >;
1084+ DropdownButtonFormField <T > get _dropdownButtonFormField => widget as DropdownButtonFormField <T >;
11281085
11291086 @override
11301087 void didChange (T ? value) {
0 commit comments