updateItem method

  1. @override
AlbumModel updateItem(
  1. AlbumModel model,
  2. AlbumEntryModel oldItem,
  3. AlbumEntryModel newItem
)
override

Implementation

@override
AlbumModel updateItem(
    AlbumModel model, AlbumEntryModel oldItem, AlbumEntryModel newItem) {
  List<AlbumEntryModel> currentItems =
      model.albumEntries == null ? [] : model.albumEntries!;
  var index = currentItems.indexOf(oldItem);
  if (index != -1) {
    var newItems = currentItems.map((e) => e).toList();
    newItems[index] = newItem;
    var newModel = model.copyWith(albumEntries: newItems);
    return newModel;
  } else {
    throw Exception("Could not find $oldItem");
  }
}