delete<S> static method

bool delete<S>({
  1. String? tag,
  2. bool force = false,
})

Delete a dependency

Implementation

static bool delete<S>({String? tag, bool force = false}) {
  final type = S;
  if (!_dependencies.containsKey(type)) {
    return false;
  }

  final builder = _dependencies[type]![tag];
  if (builder == null) {
    return false;
  }

  if (builder.permanent && !force) {
    return false;
  }

  // Call onClose if it's a controller with lifecycle
  if (builder.instance is FlowLifeCycleMixin) {
    (builder.instance as FlowLifeCycleMixin).close();
  }

  _dependencies[type]!.remove(tag);
  if (_dependencies[type]!.isEmpty) {
    _dependencies.remove(type);
  }
  return true;
}