ScopeHolder<Container extends ScopeContainer> class abstract

Simple holder for creating BaseScopeHolder.

Here is an example:

class SomeScopeHolder extends ScopeHolder<SomeScopeContainer> {}

You also have to declare SomeScopeContainer, see BaseScopeContainer.

Now you have to create an instance of this holder and use it to create/dispose scope and to communicate with it:

  final someScopeHolder = SomeScopeHolder();

  await someScopeHolder.create();

  final scope = someScopeHolder.scope;
  // Now an instance of a scope is available
  print(someScopeHolder.scope?.runtimeType); // SomeScopeContainer

  // Access [ScopeContainer] only locally. Do not store it in fields.
  if(scope != null) {
    scope.appManager.someMethod();
  }

  await someScopeHolder.drop();
  // Now scope is not available, so it's null
  print(someScopeHolder.scope?.runtimeType); // null

  // You can also subscribe to changes of a scope
  someScopeHolder.listen((scope) {
     if(scope != null) {
        // scope exists and can be used
     } else {
        // scope is not available and disposed
     }
  }

If you need to differentiate BaseScopeContainer and it's abstract interface then you better use BaseScopeHolder directly.

Inheritance

Constructors

ScopeHolder.new({List<ScopeListener>? scopeListeners, List<DepListener>? depListeners, List<AsyncDepListener>? asyncDepListeners})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scope → Container?
no setterinherited
stream Stream<Container?>
no setterinherited

Methods

create() Future<void>
inherited
createContainer() → Container
inherited
drop() Future<void>
Dispose scope. Scope becomes unavailable.
inherited
init(Container scope) Future<void>
Initialize scope. Scope becomes available and everyone can start working with it via BaseScopeHolder.
inherited
listen(StateListener<Container?> listener, {bool emitImmediately = false}) RemoveStateListener
Subscribes to the state.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited