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 ReactterInstanceManager 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:

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

$ → _ReactterHookRegister
This variable is used to register ReactterHook and attach the ReactterState that are defined here.
final
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
instanceAttached Object?
no setterinherited
isDisposed bool
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

attachTo(Object instance) → void
Attaches an object instance to this state.
inherited
detachInstance() → void
Detaches an object instance to this state.
inherited
dispose() → void
Call when this hook is no longer needed.
override
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
update([covariant Function? callback]) → void
Executes callback, and notify the listeners about to update.
inherited

Operators

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