UseDependency<T extends Object> class
A ReactterHook that allows to manages a dependency of T
with/without id.
final useAppController = UseDependency<AppController>();
final useOtherControllerWithId = UseDependency<OtherController>('uniqueId');
Use instance getter to get the T
instance:
final useAppController = UseDependency<AppController>();
print(useAppController.instance);
The instance getter returns null
, if the T
dependency is not found
or it hasn't created yet.
You can wait for the instance to be created, using UseEffect:
final useAppController = UseDependency<AppController>();
print(useAppController.instance); // return null
UseEffect(() {
print(useAppController.instance); // return instance of AppController
}, [useAppController]);
The instance must be created by DependencyInjection
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
UseDependency providers the following constructors:
- UseDependency.register: {@macro register}
- UseDependency.lazyBuilder: {@macro lazy_builder}
- UseDependency.lazyFactory: {@macro lazy_factory}
- UseDependency.lazySingleton: {@macro lazy_singleton}
- UseDependency.create: {@macro create}
- UseDependency.builder: {@macro builder}
- UseDependency.factory: {@macro factory}
- UseDependency.singleton: {@macro singleton}
- UseDependency.get: {@macro get}
IMPORTANT You should call dispose when it's no longer needed.
See also:
DependencyInjection
, a dependency manager.- UseEffect, a side-effect manager.
- Inheritance
-
- Object
- ReactterHook
- UseDependency
Constructors
- UseDependency([String? id])
-
A ReactterHook that allows to manages a dependency of
T
with/without id. -
UseDependency.builder(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.builder and creates the instance if it isn't already registered, else gets its instance only.factory -
UseDependency.create(InstanceBuilder<
T> builder, {String? id, DependencyMode mode = DependencyMode.builder}) -
Register a
builder
function of theT
dependency with/without id and creates the instance if it isn't already registered, else gets its instance only. -
UseDependency.factory(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.factory and creates the instance if it isn't already registered, else gets its instance only.factory - UseDependency.get([String? id])
-
Creates and/or gets the instance of the
T
dependency with/without id. -
UseDependency.lazyBuilder(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.builder.factory -
UseDependency.lazyFactory(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.factory.factory -
UseDependency.lazySingleton(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.singleton.factory -
UseDependency.register(InstanceBuilder<
T> builder, {DependencyMode mode = DependencyMode.builder, String? id}) -
Register a
builder
function of theT
dependency with/without id. -
UseDependency.singleton(InstanceBuilder<
T> builder, [String? id]) -
Register a
builder
function of theT
dependency with/withoutid
as DependencyMode.singleton and creates the instance if it isn't already registered, else gets its instance only.factory
Properties
- $ → HookRegister
-
This variable is used to register
Hook
and attach theStateBase
that are defined here.final - dependencyInjection → DependencyInjection
-
no setterinherited
- eventHandler → EventHandler
-
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String?
-
It's used to identify the instance of
T
dependency.final - instance → T?
-
Returns the instance if found the dependency,
or
null
if the dependency is not found it or has not been created yet.no setter - instanceBinded → Object?
-
The reference instance to the current state.
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
-
stateManagment
→ StateManagement<
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