remove method

  1. @override
void remove(
  1. Key key, {
  2. VoidCallback? onBeforeRemove,
})
override

Removes an item by key.

Implementation

@override
void remove(Key key, {VoidCallback? onBeforeRemove}) {
  final removedItem = findByKey(key);
  if (removedItem == null) return;

  // Clean up interaction state before removal
  if (isActiveKey(key)) deselect();
  if (isHoveredKey(key)) clearHover();
  if (isLongPressedKey(key)) clearLongPress();

  // Incremental Update
  _itemCache.remove(key);
  spatialIndex.remove(key);

  onBeforeRemove?.call();
  perform(logic.createRemoveOp(key), notify: true);
  _emit(ItemRemoved(removedItem));
  scheduleAutoSave();
}