updateCollectionByIndex<T> static method
Update a value in the local storage by index.
Implementation
static Future<bool> updateCollectionByIndex<T>(
int index,
T Function(T item) object, {
required String key,
}) async {
List<T> collection = await readCollection<T>(key);
// Check if the collection is empty or the index is out of bounds
if (collection.isEmpty || index < 0 || index >= collection.length) {
NyLogger.error(
'[NyStorage.updateCollectionByIndex] The collection is empty or the index is out of bounds.',
);
return false;
}
// Update the item
T newItem = object(collection[index]);
collection[index] = newItem;
await saveCollection<T>(key, collection);
return true;
}