diff --git a/packages/dropdown_button2/CHANGELOG.md b/packages/dropdown_button2/CHANGELOG.md index 0d4eaaa..bab3cdb 100644 --- a/packages/dropdown_button2/CHANGELOG.md +++ b/packages/dropdown_button2/CHANGELOG.md @@ -8,6 +8,7 @@ - Fix memory leak in CurvedAnimation [Flutter core]. - Avoid Container objects when possible for better performance [Flutter core]. - Add semantics to dropdown menu items [Flutter core]. +- Support helperStyle/helperMaxLines/errorMaxLines for DropdownButtonFormField2. ## 3.0.0-beta.21 diff --git a/packages/dropdown_button2/lib/src/dropdown_button2.dart b/packages/dropdown_button2/lib/src/dropdown_button2.dart index a2c562c..0053cd9 100644 --- a/packages/dropdown_button2/lib/src/dropdown_button2.dart +++ b/packages/dropdown_button2/lib/src/dropdown_button2.dart @@ -1006,12 +1006,15 @@ class DropdownButtonFormField2 extends FormField { return InputDecorator( decoration: const InputDecoration.collapsed(hintText: '') .updateSurroundingElements( + //helper: effectiveDecoration.helper, + helperText: effectiveDecoration.helperText, + helperStyle: effectiveDecoration.helperStyle, + helperMaxLines: effectiveDecoration.helperMaxLines, error: effectiveDecoration.error, errorText: field.errorText ?? effectiveDecoration.errorText, errorStyle: effectiveDecoration.errorStyle, - //helper: effectiveDecoration.helper, - helperText: effectiveDecoration.helperText, + errorMaxLines: effectiveDecoration.errorMaxLines, ), child: DropdownButtonHideUnderline( child: DropdownButton2._formField( @@ -1047,21 +1050,15 @@ class DropdownButtonFormField2 extends FormField { // that surrounds the DropdownButton FormField. This setup is crucial // to prevent the inkwell from covering the error or helper widget // and to ensure that the menu does not open below them. - .updateSurroundingElements( - error: null, - errorText: null, - errorStyle: null, - //helper: null, - helperText: null, - ) + .emptySurroundingElements // This is crucial for the error border functionality to work. .copyWith( - error: field.hasError || - effectiveDecoration.error != null || - effectiveDecoration.errorText != null - ? const SizedBox.shrink() - : null, - ), + error: field.hasError || + effectiveDecoration.error != null || + effectiveDecoration.errorText != null + ? const SizedBox.shrink() + : null, + ), isEmpty: isEmpty, isFocused: Focus.of(context).hasFocus, ), diff --git a/packages/dropdown_button2/lib/src/utils.dart b/packages/dropdown_button2/lib/src/utils.dart index 5815180..59571cd 100644 --- a/packages/dropdown_button2/lib/src/utils.dart +++ b/packages/dropdown_button2/lib/src/utils.dart @@ -67,12 +67,15 @@ class _ConditionalDecoratedBox extends StatelessWidget { extension _InputDecorationExtension on InputDecoration { InputDecoration updateSurroundingElements({ - required Widget? error, - required String? errorText, - required TextStyle? errorStyle, // TODO(Ahmed): Add this when it's supported by the min version of the package [Flutter>=3.22.0]. // required Widget? helper, required String? helperText, + required TextStyle? helperStyle, + required int? helperMaxLines, + required Widget? error, + required String? errorText, + required TextStyle? errorStyle, + required int? errorMaxLines, }) { return InputDecoration( icon: icon, @@ -130,4 +133,14 @@ extension _InputDecorationExtension on InputDecoration { constraints: constraints, ); } + + InputDecoration get emptySurroundingElements => updateSurroundingElements( + helperText: null, + helperStyle: null, + helperMaxLines: null, + error: null, + errorText: null, + errorStyle: null, + errorMaxLines: null, + ); }