removeObjectReferenceInScope method
Removes object in given scope
Implementation
void removeObjectReferenceInScope({
required Type type,
required String scopeId,
int? index,
}) {
final scopedReferences = _references[scopeId];
if (index == null) {
scopedReferences?.remove(type);
} else {
final refs = scopedReferences?[type] ?? [];
if (refs.isEmpty) {
return;
}
if (index < 0 || index >= refs.length) {
throw IllegalArgumentException(
message:
'The index = $index value must be non-negative and less than count of references of $type in $scopeId.',
);
}
refs.removeAt(index);
if (refs.isEmpty) {
scopedReferences?.remove(type);
}
}
if (scopedReferences?.isEmpty ?? true) {
_references.remove(scopeId);
}
}