UseInstance<T extends Object> class

A ReactterHook that allows to manages an instance of T with/without id.

final useAppController = UseInstance<AppController>();
final useOtherControllerWithId = UseInstance<OtherController>('uniqueId');

Use instance getter to get the T instance:

final useAppController = UseInstance<AppController>();
print(useAppController.instance);

The instance getter returns null, if the T instance is not found or it hasn't created yet. You can wait for the instance to be created, using UseEffect:

final useAppController = UseInstance<AppController>();
print(useAppController.instance); // return null

UseEffect(() {
  print(useAppController.instance); // return instance of AppController
}, [useAppController]);

The instance must be created by InstanceManager using the following methods:

  • Reactter.get: {@macro get}
  • Reactter.create: {@macro create}
  • Reactter.builder: {@macro builder}
  • Reactter.singleton: {@macro builder}

or created by ReactterProvider of flutter_reactter

UseInstance providers the following constructors:

IMPORTANT You should call dispose when it's no longer needed.

See also:

  • InstanceManager, a instances manager.
  • UseEffect, a side-effect manager.
Inheritance

Constructors

UseInstance([String? id])
A ReactterHook that allows to manages an instance of T with/without id.
UseInstance.builder(InstanceBuilder<T> builder, [String? id])
It's a ways to manage an instance, which registers a builder function and creates the instance, unless it has already done so.
factory
UseInstance.create(InstanceBuilder<T> builder, {String? id, InstanceManageMode mode = InstanceManageMode.builder})
Registers, creates and/or gets the instance of T with an id optional.
UseInstance.factory(InstanceBuilder<T> builder, [String? id])
It's a ways to manage an instance, which registers a builder function only once and creates the instance if not already done.
factory
UseInstance.get([String? id])
Creates and/or gets the instance of T with an id optional.
UseInstance.lazyBuilder(InstanceBuilder<T> builder, [String? id])
Register a builder function for creating a new instance of T with an id optional as InstanceManageMode.builder.
factory
UseInstance.lazyFactory(InstanceBuilder<T> builder, [String? id])
Register a builder function for creating a new instance of T with an id optional as InstanceManageMode.factory.
factory
UseInstance.lazySingleton(InstanceBuilder<T> builder, [String? id])
Register a builder function for creating a new instance of T with an id optional as InstanceManageMode.singleton.
factory
UseInstance.register(InstanceBuilder<T> builder, {InstanceManageMode mode = InstanceManageMode.builder, String? id})
Register a builder function for creating a new instance of T with an id optional.
UseInstance.singleton(InstanceBuilder<T> builder, [String? id])
It's a ways to manage a instance, which registers a builder function and creates the instance only once.
factory

Properties

$ → HookRegister
This variable is used to register Hook and attach the StateBase that are defined here.
final
eventManager → EventManager
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
id String?
It's used to identify the instance of T type.
final
instance → T?
Returns the instance if found it, or null if the instance is not found it or has not been created yet.
no setter
instanceBinded Object?
The reference instance to the current state.
no setterinherited
instanceManager → InstanceManager
no setterinherited
isDisposed bool
Returns true if the state has been disposed.
no setterinherited
logger → Logger
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateManager → StateManager<StateBase>
no setterinherited

Methods

bind(Object instance) → void
Stores a reference to an object instance
inherited
dispose() → void
Call when this hook is no longer needed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh() → void
It's used to notify listeners that the state has been updated. It is typically called after making changes to the state object.
inherited
toString() String
A string representation of this object.
inherited
unbind() → void
Removes the reference to the object instance
inherited
update([covariant Function? callback]) → void
Executes callback, and notifies the listeners about the update.
inherited

Operators

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