Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dropdown_button2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 12 additions & 15 deletions packages/dropdown_button2/lib/src/dropdown_button2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,15 @@ class DropdownButtonFormField2<T> extends FormField<T> {
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<T>._formField(
Expand Down Expand Up @@ -1047,21 +1050,15 @@ class DropdownButtonFormField2<T> extends FormField<T> {
// 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,
),
Expand Down
19 changes: 16 additions & 3 deletions packages/dropdown_button2/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
}