removeAtEmit method
Removes an item at the specified index. Returns the removed item, or null if index is out of bounds.
Implementation
@override
T? removeAtEmit(int index) {
final currentState = state;
if (currentState is! SmartPaginationLoaded<T>) return null;
final updated = List<T>.from(currentState.allItems);
if (index < 0 || index >= updated.length) return null;
final removedItem = updated.removeAt(index);
_onInsertionCallback?.call(updated);
_refreshDataAge();
emit(
currentState.copyWith(
allItems: updated,
items: updated,
lastUpdate: DateTime.now(),
fetchedAt: _lastFetchTime,
dataExpiredAt: _getDataExpiredAt(),
),
);
return removedItem;
}