Skip to content

Commit f59ed66

Browse files
committed
reactive_dropdown_search 6.0.0-pre4
1 parent 27b3727 commit f59ed66

File tree

4 files changed

+67
-29
lines changed

4 files changed

+67
-29
lines changed

packages/reactive_dropdown_search/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [6.0.0-pre4]
2+
3+
* add reference to original valueAccessor for items accessor
4+
15
## [6.0.0-pre3]
26

37
* Split value item and value accessors

packages/reactive_dropdown_search/lib/src/reactive_dropdown_search.dart

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ import 'package:reactive_forms/reactive_forms.dart';
1010
abstract class DropDownSearchValueAccessor<T, V> {
1111
DropDownSearchValueAccessor();
1212

13-
V? modelToViewValue(List<V> items, T? modelValue);
14-
15-
T? viewToModelValue(List<V> items, V? modelValue);
13+
V? modelToViewValue(
14+
List<V> items,
15+
T? modelValue,
16+
ControlValueAccessor<T, V> accessor,
17+
);
18+
19+
T? viewToModelValue(
20+
List<V> items,
21+
V? modelValue,
22+
ControlValueAccessor<T, V> accessor,
23+
);
1624
}
1725

1826
class _DropDownSearchValueAccessor<T, V> extends ControlValueAccessor<T, V> {
@@ -29,7 +37,11 @@ class _DropDownSearchValueAccessor<T, V> extends ControlValueAccessor<T, V> {
2937
V? modelToViewValue(T? modelValue) {
3038
final result = items?.call('', null) ?? [];
3139
if (result is List<V>) {
32-
return dropDownValueAccessor.modelToViewValue(result, modelValue);
40+
return dropDownValueAccessor.modelToViewValue(
41+
result,
42+
modelValue,
43+
this,
44+
);
3345
}
3446

3547
throw UnsupportedError('Asynchronously fetched values are not supported');
@@ -40,7 +52,11 @@ class _DropDownSearchValueAccessor<T, V> extends ControlValueAccessor<T, V> {
4052
final result = items?.call('', null) ?? [];
4153

4254
if (result is List<V>) {
43-
return dropDownValueAccessor.viewToModelValue(result, viewValue);
55+
return dropDownValueAccessor.viewToModelValue(
56+
result,
57+
viewValue,
58+
this,
59+
);
4460
}
4561

4662
throw UnsupportedError('Asynchronously fetched values are not supported');
@@ -145,15 +161,16 @@ class ReactiveDropdownSearch<T, V> extends ReactiveFormField<T, V> {
145161
BeforePopupOpening<V>? onBeforePopupOpening,
146162
Widget Function(BuildContext context, String error)? errorBuilder,
147163
}) : super(
148-
valueAccessor: switch(valueAccessor) {
164+
valueAccessor: switch (valueAccessor) {
149165
ControlValueAccessor<T, V>() => valueAccessor,
150-
null => switch(valueItemAccessor) {
151-
DropDownSearchValueAccessor<T, V>() => _DropDownSearchValueAccessor(
152-
items: items,
153-
dropDownValueAccessor: valueItemAccessor,
154-
),
155-
null => null,
156-
},
166+
null => switch (valueItemAccessor) {
167+
DropDownSearchValueAccessor<T, V>() =>
168+
_DropDownSearchValueAccessor(
169+
items: items,
170+
dropDownValueAccessor: valueItemAccessor,
171+
),
172+
null => null,
173+
},
157174
},
158175
builder: (field) {
159176
final effectiveDecoration = dropdownDecoratorProps.decoration

packages/reactive_dropdown_search/lib/src/reactive_dropdown_search_multiselection.dart

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ import 'package:reactive_forms/reactive_forms.dart';
1010
abstract class DropDownSearchMultiSelectionValueAccessor<T, V> {
1111
DropDownSearchMultiSelectionValueAccessor();
1212

13-
List<V>? modelToViewValue(List<V> items, List<T>? modelValue);
14-
15-
List<T>? viewToModelValue(List<V> items, List<V>? modelValue);
13+
List<V>? modelToViewValue(
14+
List<V> items,
15+
List<T>? modelValue,
16+
ControlValueAccessor<List<T>, List<V>> accessor,
17+
);
18+
19+
List<T>? viewToModelValue(
20+
List<V> items,
21+
List<V>? modelValue,
22+
ControlValueAccessor<List<T>, List<V>> accessor,
23+
);
1624
}
1725

1826
class _DropDownSearchMultiSelectionValueAccessor<T, V>
@@ -30,7 +38,11 @@ class _DropDownSearchMultiSelectionValueAccessor<T, V>
3038
List<V>? modelToViewValue(List<T>? modelValue) {
3139
final result = items?.call('', null) ?? [];
3240
if (result is List<V>) {
33-
return dropDownValueAccessor.modelToViewValue(result, modelValue);
41+
return dropDownValueAccessor.modelToViewValue(
42+
result,
43+
modelValue,
44+
this,
45+
);
3446
}
3547

3648
throw UnsupportedError('Asynchronously fetched values are not supported');
@@ -41,7 +53,11 @@ class _DropDownSearchMultiSelectionValueAccessor<T, V>
4153
final result = items?.call('', null) ?? [];
4254

4355
if (result is List<V>) {
44-
return dropDownValueAccessor.viewToModelValue(result, viewValue);
56+
return dropDownValueAccessor.viewToModelValue(
57+
result,
58+
viewValue,
59+
this,
60+
);
4561
}
4662

4763
throw UnsupportedError('Asynchronously fetched values are not supported');
@@ -148,16 +164,17 @@ class ReactiveDropdownSearchMultiSelection<T, V>
148164
BeforePopupOpeningMultiSelection<V>? onBeforePopupOpening,
149165
Widget Function(BuildContext context, String error)? errorBuilder,
150166
}) : super(
151-
valueAccessor: switch(valueAccessor) {
152-
ControlValueAccessor<List<T>, List<V>>() => valueAccessor,
153-
null => switch(valueItemAccessor) {
154-
DropDownSearchMultiSelectionValueAccessor<T, V>() => _DropDownSearchMultiSelectionValueAccessor(
155-
items: items,
156-
dropDownValueAccessor: valueItemAccessor,
157-
),
158-
null => null,
159-
},
160-
},
167+
valueAccessor: switch (valueAccessor) {
168+
ControlValueAccessor<List<T>, List<V>>() => valueAccessor,
169+
null => switch (valueItemAccessor) {
170+
DropDownSearchMultiSelectionValueAccessor<T, V>() =>
171+
_DropDownSearchMultiSelectionValueAccessor(
172+
items: items,
173+
dropDownValueAccessor: valueItemAccessor,
174+
),
175+
null => null,
176+
},
177+
},
161178
builder: (field) {
162179
final effectiveDecoration = dropdownDecoratorProps.decoration
163180
?.applyDefaults(Theme.of(field.context).inputDecorationTheme);

packages/reactive_dropdown_search/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: reactive_dropdown_search
22
description: Wrapper around searchable_dropdown to use with reactive_forms
3-
version: 6.0.0-pre3
3+
version: 6.0.0-pre4
44
repository: https://github.com/artflutter/reactive_forms_widgets/tree/master/packages/reactive_dropdown_search
55
issue_tracker: https://github.com/artflutter/reactive_forms_widgets/issues
66

0 commit comments

Comments
 (0)