addWithParams<InputState> method

void addWithParams<InputState>({
  1. required String type,
  2. InputState? params,
  3. int? index,
  4. String? scope,
})

Adds instance in collection

Also calls MvvmInstance.initialize for this isntance

type - string type of this instance index - index for this instance scope - string scope to get instance from params - params for this instance

Implementation

void addWithParams<InputState>({
  required String type,
  InputState? params,
  int? index,
  String? scope,
}) {
  final id = type;
  final scopeId = scope ?? BaseScopes.global;

  if (container.contains(scopeId, id, index) && index == null) {
    return;
  }

  final builder = builders[id];

  final newInstance = builder!() as MvvmInstance;

  container.addObjectInScope(
    object: newInstance,
    type: type,
    scopeId: scopeId,
  );

  if (!newInstance.isInitialized) {
    newInstance.initialize(params);
  }
}