Skip to content

Commit

Permalink
reactive_dropdown_search 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Sep 21, 2024
1 parent ba30b0e commit 53e35d8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 57 deletions.
4 changes: 4 additions & 0 deletions packages/reactive_dropdown_search/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [5.0.4]

* errorBuilder

## [5.0.3]

* ffi dependency fix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _DropDownSearchValueAccessor<T, V> extends ControlValueAccessor<T, V> {
@override
V? modelToViewValue(T? modelValue) {
final result = items?.call('', null) ?? [];
if(result is List<V>) {
if (result is List<V>) {
return dropDownValueAccessor.modelToViewValue(result, modelValue);
}

Expand All @@ -39,7 +39,7 @@ class _DropDownSearchValueAccessor<T, V> extends ControlValueAccessor<T, V> {
T? viewToModelValue(V? viewValue) {
final result = items?.call('', null) ?? [];

if(result is List<V>) {
if (result is List<V>) {
return dropDownValueAccessor.viewToModelValue(result, viewValue);
}

Expand Down Expand Up @@ -142,44 +142,63 @@ class ReactiveDropdownSearch<T, V> extends ReactiveFormField<T, V> {
DropDownDecoratorProps dropdownDecoratorProps =
const DropDownDecoratorProps(),
BeforePopupOpening<V>? onBeforePopupOpening,
Widget Function(BuildContext context, String error)? errorBuilder,
}) : super(
valueAccessor: valueAccessor != null
? _DropDownSearchValueAccessor(
items: items,
dropDownValueAccessor: valueAccessor,
)
: null,
builder: (field) {
final effectiveDecoration = dropdownDecoratorProps.decoration
.applyDefaults(Theme.of(field.context).inputDecorationTheme);

return DropdownSearch<V>(
key: widgetKey,
onChanged: field.didChange,
popupProps: popupProps,
selectedItem: field.value,
dropdownBuilder: dropdownBuilder,
enabled: field.control.enabled,
filterFn: filterFn,
itemAsString: itemAsString,
compareFn: compareFn,
mode: mode,
onSaved: onSaved,
onBeforeChange: onBeforeChange,
onBeforePopupOpening: onBeforePopupOpening,
decoratorProps: DropDownDecoratorProps(
decoration:
effectiveDecoration.copyWith(errorText: field.errorText),
baseStyle: dropdownDecoratorProps.baseStyle,
textAlign: dropdownDecoratorProps.textAlign,
textAlignVertical: dropdownDecoratorProps.textAlignVertical,
expands: dropdownDecoratorProps.expands,
isHovering: dropdownDecoratorProps.isHovering,
),
suffixProps: suffixProps,
clickProps: clickProps,
items: items,
);
},
);
}
valueAccessor: valueAccessor != null
? _DropDownSearchValueAccessor(
items: items,
dropDownValueAccessor: valueAccessor,
)
: null,
builder: (field) {
final effectiveDecoration = dropdownDecoratorProps.decoration
.applyDefaults(Theme.of(field.context).inputDecorationTheme);

final errorText = field.errorText;

return DropdownSearch<V>(
key: widgetKey,
onChanged: field.didChange,
popupProps: popupProps,
selectedItem: field.value,
dropdownBuilder: dropdownBuilder,
enabled: field.control.enabled,
filterFn: filterFn,
itemAsString: itemAsString,
compareFn: compareFn,
mode: mode,
onSaved: onSaved,
onBeforeChange: onBeforeChange,
onBeforePopupOpening: onBeforePopupOpening,
decoratorProps: DropDownDecoratorProps(
decoration: effectiveDecoration.copyWith(
errorText: errorBuilder == null ? errorText : null,
error: errorBuilder != null && errorText != null
? DefaultTextStyle(
style: Theme.of(field.context)
.textTheme
.bodySmall
?.copyWith(
color: Theme.of(field.context)
.colorScheme
.error,
) ??
const TextStyle(),
child:
errorBuilder.call(field.context, errorText),
)
: null,
),
baseStyle: dropdownDecoratorProps.baseStyle,
textAlign: dropdownDecoratorProps.textAlign,
textAlignVertical: dropdownDecoratorProps.textAlignVertical,
expands: dropdownDecoratorProps.expands,
isHovering: dropdownDecoratorProps.isHovering,
),
suffixProps: suffixProps,
clickProps: clickProps,
items: items,
);
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _DropDownSearchMultiSelectionValueAccessor<T, V>
@override
List<V>? modelToViewValue(List<T>? modelValue) {
final result = items?.call('', null) ?? [];
if(result is List<V>) {
if (result is List<V>) {
return dropDownValueAccessor.modelToViewValue(result, modelValue);
}

Expand All @@ -40,7 +40,7 @@ class _DropDownSearchMultiSelectionValueAccessor<T, V>
List<T>? viewToModelValue(List<V>? viewValue) {
final result = items?.call('', null) ?? [];

if(result is List<V>) {
if (result is List<V>) {
return dropDownValueAccessor.viewToModelValue(result, viewValue);
}

Expand Down Expand Up @@ -145,16 +145,19 @@ class ReactiveDropdownSearchMultiSelection<T, V>
DropDownDecoratorProps dropdownDecoratorProps =
const DropDownDecoratorProps(),
BeforePopupOpeningMultiSelection<V>? onBeforePopupOpening,
Widget Function(BuildContext context, String error)? errorBuilder,
}) : super(
valueAccessor: valueAccessor != null
? _DropDownSearchMultiSelectionValueAccessor(
items: items,
dropDownValueAccessor: valueAccessor,
)
: null,
builder: (field) {
final effectiveDecoration = dropdownDecoratorProps.decoration
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
valueAccessor: valueAccessor != null
? _DropDownSearchMultiSelectionValueAccessor(
items: items,
dropDownValueAccessor: valueAccessor,
)
: null,
builder: (field) {
final effectiveDecoration = dropdownDecoratorProps.decoration
.applyDefaults(Theme.of(field.context).inputDecorationTheme);

final errorText = field.errorText;

return DropdownSearch<V>.multiSelection(
key: widgetKey,
Expand All @@ -173,8 +176,24 @@ class ReactiveDropdownSearchMultiSelection<T, V>
itemAsString: itemAsString,
compareFn: compareFn,
decoratorProps: DropDownDecoratorProps(
decoration:
effectiveDecoration.copyWith(errorText: field.errorText),
decoration: effectiveDecoration.copyWith(
errorText: errorBuilder == null ? errorText : null,
error: errorBuilder != null && errorText != null
? DefaultTextStyle(
style: Theme.of(field.context)
.textTheme
.bodySmall
?.copyWith(
color: Theme.of(field.context)
.colorScheme
.error,
) ??
const TextStyle(),
child:
errorBuilder.call(field.context, errorText),
)
: null,
),
baseStyle: dropdownDecoratorProps.baseStyle,
textAlign: dropdownDecoratorProps.textAlign,
textAlignVertical: dropdownDecoratorProps.textAlignVertical,
Expand All @@ -187,4 +206,4 @@ class ReactiveDropdownSearchMultiSelection<T, V>
);
},
);
}
}
2 changes: 1 addition & 1 deletion packages/reactive_dropdown_search/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: reactive_dropdown_search
description: Wrapper around searchable_dropdown to use with reactive_forms
version: 5.0.3
version: 5.0.4
repository: https://github.com/artflutter/reactive_forms_widgets/tree/master/packages/reactive_dropdown_search
issue_tracker: https://github.com/artflutter/reactive_forms_widgets/issues

Expand Down

0 comments on commit 53e35d8

Please sign in to comment.