Skip to content

Commit 6b078ac

Browse files
authored
Merge pull request #354 from AhmedLSayed9/support_more_formfield_surrounding_elements
Support helperStyle/helperMaxLines/errorMaxLines for DropdownButtonFo…
2 parents 75e5c51 + adfb5c1 commit 6b078ac

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix memory leak in CurvedAnimation [Flutter core].
99
- Avoid Container objects when possible for better performance [Flutter core].
1010
- Add semantics to dropdown menu items [Flutter core].
11+
- Support helperStyle/helperMaxLines/errorMaxLines for DropdownButtonFormField2.
1112

1213
## 3.0.0-beta.21
1314

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,15 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10061006
return InputDecorator(
10071007
decoration: const InputDecoration.collapsed(hintText: '')
10081008
.updateSurroundingElements(
1009+
//helper: effectiveDecoration.helper,
1010+
helperText: effectiveDecoration.helperText,
1011+
helperStyle: effectiveDecoration.helperStyle,
1012+
helperMaxLines: effectiveDecoration.helperMaxLines,
10091013
error: effectiveDecoration.error,
10101014
errorText:
10111015
field.errorText ?? effectiveDecoration.errorText,
10121016
errorStyle: effectiveDecoration.errorStyle,
1013-
//helper: effectiveDecoration.helper,
1014-
helperText: effectiveDecoration.helperText,
1017+
errorMaxLines: effectiveDecoration.errorMaxLines,
10151018
),
10161019
child: DropdownButtonHideUnderline(
10171020
child: DropdownButton2<T>._formField(
@@ -1047,21 +1050,15 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10471050
// that surrounds the DropdownButton FormField. This setup is crucial
10481051
// to prevent the inkwell from covering the error or helper widget
10491052
// and to ensure that the menu does not open below them.
1050-
.updateSurroundingElements(
1051-
error: null,
1052-
errorText: null,
1053-
errorStyle: null,
1054-
//helper: null,
1055-
helperText: null,
1056-
)
1053+
.emptySurroundingElements
10571054
// This is crucial for the error border functionality to work.
10581055
.copyWith(
1059-
error: field.hasError ||
1060-
effectiveDecoration.error != null ||
1061-
effectiveDecoration.errorText != null
1062-
? const SizedBox.shrink()
1063-
: null,
1064-
),
1056+
error: field.hasError ||
1057+
effectiveDecoration.error != null ||
1058+
effectiveDecoration.errorText != null
1059+
? const SizedBox.shrink()
1060+
: null,
1061+
),
10651062
isEmpty: isEmpty,
10661063
isFocused: Focus.of(context).hasFocus,
10671064
),

packages/dropdown_button2/lib/src/utils.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ class _ConditionalDecoratedBox extends StatelessWidget {
6767

6868
extension _InputDecorationExtension on InputDecoration {
6969
InputDecoration updateSurroundingElements({
70-
required Widget? error,
71-
required String? errorText,
72-
required TextStyle? errorStyle,
7370
// TODO(Ahmed): Add this when it's supported by the min version of the package [Flutter>=3.22.0].
7471
// required Widget? helper,
7572
required String? helperText,
73+
required TextStyle? helperStyle,
74+
required int? helperMaxLines,
75+
required Widget? error,
76+
required String? errorText,
77+
required TextStyle? errorStyle,
78+
required int? errorMaxLines,
7679
}) {
7780
return InputDecoration(
7881
icon: icon,
@@ -130,4 +133,14 @@ extension _InputDecorationExtension on InputDecoration {
130133
constraints: constraints,
131134
);
132135
}
136+
137+
InputDecoration get emptySurroundingElements => updateSurroundingElements(
138+
helperText: null,
139+
helperStyle: null,
140+
helperMaxLines: null,
141+
error: null,
142+
errorText: null,
143+
errorStyle: null,
144+
errorMaxLines: null,
145+
);
133146
}

0 commit comments

Comments
 (0)