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