insertEmit method
Inserts an item at the specified index.
Implementation
@override
void insertEmit(T item, {int index = 0}) {
final currentState = state;
if (currentState is! SmartPaginationLoaded<T>) return;
final updated = List<T>.from(currentState.allItems);
// Use sorted insertion if sorting is active, otherwise use the provided index
final insertIndex = _findSortedInsertIndex(updated, item, fallbackIndex: index);
updated.insert(insertIndex, item);
_onInsertionCallback?.call(updated);
_refreshDataAge();
emit(
currentState.copyWith(
allItems: updated,
items: updated,
lastUpdate: DateTime.now(),
fetchedAt: _lastFetchTime,
dataExpiredAt: _getDataExpiredAt(),
),
);
}