# updateItem method Null safety

1. @override

GridModel updateItem(

1. GridModel model,
2. BodyComponentModel oldItem,
3. 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");
      }
    }