insertIdInList method
Implementation
void insertIdInList(
String queryKey,
String id,
Object position, {
String? entityType,
}) {
_write(() {
final prev = _lists[queryKey] ?? ListState.empty;
if (entityType != null) _listTypes[queryKey] = entityType;
final isNew = !prev.ids.contains(id);
final ids = prev.ids.where((e) => e != id).toList();
if (position == 'start') {
ids.insert(0, id);
} else if (position == 'end') {
ids.add(id);
} else if (position is int) {
ids.insert(position.clamp(0, ids.length), id);
}
_lists[queryKey] = prev.copyWith(
ids: List.unmodifiable(ids),
total: isNew && prev.total != null ? prev.total! + 1 : prev.total,
);
_notifyList(queryKey);
});
}