@@ -127,7 +127,8 @@ class DropdownButton2<T> extends StatefulWidget {
127127 'Only one of valueListenable or multiValueListenable can be used.' ,
128128 ),
129129 _inputDecoration = null ,
130- _isEmpty = false ;
130+ _isEmpty = false ,
131+ _hasError = false ;
131132
132133 const DropdownButton2 ._formField ({
133134 super .key,
@@ -161,9 +162,11 @@ class DropdownButton2<T> extends StatefulWidget {
161162 required this .openDropdownListenable,
162163 required InputDecoration inputDecoration,
163164 required bool isEmpty,
165+ required bool hasError,
164166 }) : underline = null ,
165167 _inputDecoration = inputDecoration,
166- _isEmpty = isEmpty;
168+ _isEmpty = isEmpty,
169+ _hasError = hasError;
167170
168171 /// The list of items the user can select.
169172 ///
@@ -382,6 +385,8 @@ class DropdownButton2<T> extends StatefulWidget {
382385
383386 final bool _isEmpty;
384387
388+ final bool _hasError;
389+
385390 @override
386391 State <DropdownButton2 <T >> createState () => _DropdownButton2State <T >();
387392}
@@ -572,6 +577,30 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
572577 }
573578 }
574579
580+ Set <WidgetState > _materialState (InputDecoration decoration) => < WidgetState > {
581+ if (! decoration.enabled) WidgetState .disabled,
582+ if (_isFocused) WidgetState .focused,
583+ if (_isHovering) WidgetState .hovered,
584+ if (widget._hasError) WidgetState .error,
585+ };
586+
587+ BorderRadius ? _getInputDecorationBorderRadius (InputDecoration decoration) {
588+ InputBorder ? border;
589+ if (! decoration.enabled) {
590+ border = widget._hasError ? decoration.errorBorder : decoration.disabledBorder;
591+ } else if (_isFocused) {
592+ border = widget._hasError ? decoration.focusedErrorBorder : decoration.focusedBorder;
593+ } else {
594+ border = widget._hasError ? decoration.errorBorder : decoration.enabledBorder;
595+ }
596+ border ?? = WidgetStateProperty .resolveAs (decoration.border, _materialState (decoration));
597+
598+ if (border is OutlineInputBorder ) {
599+ return border.borderRadius;
600+ }
601+ return null ;
602+ }
603+
575604 EdgeInsetsGeometry _buttonAdditionalHPadding () {
576605 final TextDirection ? textDirection = Directionality .maybeOf (context);
577606
@@ -602,7 +631,9 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
602631 _dropdownRoute = _DropdownRoute <T >(
603632 items: items,
604633 buttonRect: _buttonRect,
605- buttonBorderRadius: _getButtonBorderRadius (context) ?? BorderRadius .zero,
634+ buttonBorderRadius: widget._inputDecoration != null
635+ ? _getInputDecorationBorderRadius (widget._inputDecoration! )
636+ : _getButtonBorderRadius (context),
606637 selectedIndex: _selectedIndex ?? 0 ,
607638 isNoSelectedItem: _selectedIndex == null ,
608639 onChanged: widget.onChanged,
@@ -1027,6 +1058,10 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10271058 : effectiveHint != null || effectiveDisabledHint != null ;
10281059 final bool isEmpty = ! showSelectedItem && ! isHintOrDisabledHintAvailable;
10291060
1061+ final bool hasError = field.hasError ||
1062+ effectiveDecoration.errorText != null ||
1063+ effectiveDecoration.error != null ;
1064+
10301065 // An unFocusable Focus widget so that this widget can detect if its
10311066 // descendants have focus or not.
10321067 return Focus (
@@ -1068,6 +1103,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10681103 hintText: effectiveDecoration.hintText != null ? '' : null ,
10691104 ),
10701105 isEmpty: isEmpty,
1106+ hasError: hasError,
10711107 ),
10721108 ),
10731109 );
0 commit comments