updateItem method

  1. @override
FollowingDashboardModel updateItem(
  1. FollowingDashboardModel model,
  2. MemberActionModel oldItem,
  3. MemberActionModel newItem
)
override

Implementation

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