addToCollection<T> static method
Add a newItem to the collection using a key
.
Implementation
static Future addToCollection<T>(String key,
{required dynamic item,
bool allowDuplicates = true,
Map<Type, dynamic>? modelDecoders}) async {
List<T> collection =
await readCollection<T>(key, modelDecoders: modelDecoders);
if (allowDuplicates == false) {
if (collection.any((collect) => collect == item)) {
return;
}
}
collection.add(item);
await saveCollection<T>(key, collection);
}