updateItem method
GridModel
updateItem(
- GridModel model,
- BodyComponentModel oldItem,
- BodyComponentModel newItem
override
Implementation
@override
GridModel updateItem(
GridModel 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");
}
}