updateItem method

  1. @override
FaderModel updateItem(
  1. FaderModel model,
  2. ListedItemModel oldItem,
  3. ListedItemModel newItem
)
override

Implementation

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