updateCollectionWhere<T> static method

Future updateCollectionWhere<T>(
  1. bool where(
    1. dynamic value
    ), {
  2. required String key,
  3. required T update(
    1. dynamic value
    ),
})

Update item(s) in a collection using a where query.

Implementation

static Future updateCollectionWhere<T>(bool Function(dynamic value) where,
    {required String key, required T Function(dynamic value) update}) async {
  List<T> collection = await readCollection<T>(key);
  if (collection.isEmpty) return;

  collection.where((value) => where(value)).forEach((element) {
    update(element);
  });

  await saveCollection<T>(key, collection);
}