updateItemByKey method

void updateItemByKey(
  1. K key,
  2. T item
)

Implementation

void updateItemByKey(K key, T item) {
  if (!_itemsMap.containsKey(key)) {
    throw ArgumentError.value(key, 'key', 'Item not found');
  }

  _itemsMap[key] = item;

  if (!isServerSide) {
    final index = _localPaginationItems.indexWhere((x) => itemKey(x) == key);
    if (index != -1) {
      _localPaginationItems[index] = item;
    }
  }

  final displayItems = value.displayItems;
  final index = displayItems.indexWhere((x) => x.key == key);
  if (index > -1) {
    updateState(
      who: 'updateItem',
      displayItems: displayItems.copyWithReplacedAt(index, displayItems[index].copyWith(data: item)),
    );
  }
}