Skip to content

Commit 3487bfb

Browse files
feat: add assert when change items and not change initial value
1 parent c3a8fda commit 3487bfb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/src/fields/form_builder_dropdown.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ class _FormBuilderDropdownState<T>
308308
final currentlyChilds =
309309
widget.items.map((e) => e.child.toString()).toList();
310310

311+
if (!currentlyValues.contains(initialValue) &&
312+
!initialValue.emptyValidator()) {
313+
assert(
314+
currentlyValues.contains(initialValue) && initialValue.emptyValidator(),
315+
'The initialValue [$initialValue] is not in the list of items or is not null or empty. '
316+
'Please provide one of the items as the initialValue or update your initial value. '
317+
'By default, will apply [null] to field value',
318+
);
319+
setValue(null);
320+
}
321+
311322
if ((!listEquals(oldChilds, currentlyChilds) ||
312323
!listEquals(oldValues, currentlyValues)) &&
313324
(currentlyValues.contains(initialValue) ||

0 commit comments

Comments
 (0)