updateItem method

  1. @override
PresentationModel updateItem(
  1. PresentationModel model,
  2. BodyComponentModel oldItem,
  3. BodyComponentModel newItem
)
override

Implementation

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