putIterableIfNotEmpty method
Maps name
to collection
after wrapping it in a List, clobbering any existing
name/value mapping with the same name. If the collection is empty, any existing mapping
for name
is removed.
If the objects in collection
are JSONable, then they are converted to Map first.
Implementation
void putIterableIfNotEmpty(String name, Iterable<dynamic>? collection) {
List list = collection?.whereNotNull().mapNotNull(_wrapJSON).toList() ?? [];
if (list.isEmpty) {
this?.remove(name);
return;
}
put(name, list);
}