arrayUpdate static method
Update the array in the field
of the Document ref
with the given
List of values
.
If add
is true, the values
will be added to ref
and removed
otherwise.
Implementation
static Future<void> arrayUpdate({
required DocumentReference ref,
required String field,
required List<dynamic> values,
bool add = true,
}) async {
assert(field.isNotEmpty);
assert(values.isNotEmpty);
if (add) {
return await ref.update({
field: FieldValue.arrayUnion(values),
});
} else {
return await ref.update({
field: FieldValue.arrayRemove(values),
});
}
}