UseDependency<T extends Object> class
A RtHook 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:
- Rt.get: {@macro reactter.get}
- Rt.create: {@macro reactter.create}
- Rt.builder: {@macro reactter.builder}
- Rt.singleton: {@macro reactter.builder}
or created by RtProvider of flutter_reactter
UseDependency providers the following constructors:
- UseDependency.register: {@macro reactter.register}
- UseDependency.lazyBuilder: {@macro reactter.lazy_builder}
- UseDependency.lazyFactory: {@macro lazy_factory}
- UseDependency.lazySingleton: {@macro reactter.lazy_singleton}
- UseDependency.create: {@macro reactter.create}
- UseDependency.builder: {@macro reactter.builder}
- UseDependency.factory: {@macro reactter.factory}
- UseDependency.singleton: {@macro reactter.singleton}
- UseDependency.get: {@macro reactter.get}
IMPORTANT You should call dispose when it's no longer needed.
See also:
DependencyInjection, a dependency manager.- UseEffect, a side-effect manager.
Constructors
- UseDependency({String? id, String? debugLabel})
-
A RtHook that allows to manages a dependency of
Twith/without id. -
UseDependency.builder(InstanceBuilder<
T> builder, {String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas 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, String? debugLabel}) -
Register a
builderfunction of theTdependency 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, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas DependencyMode.factory and creates the instance if it isn't already registered, else gets its instance only.factory - UseDependency.get({String? id, String? debugLabel})
-
Creates and/or gets the instance of the
Tdependency with/without id. -
UseDependency.lazyBuilder(InstanceBuilder<
T> builder, {String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas DependencyMode.builder.factory -
UseDependency.lazyFactory(InstanceBuilder<
T> builder, {String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas DependencyMode.factory.factory -
UseDependency.lazySingleton(InstanceBuilder<
T> builder, {String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas DependencyMode.singleton.factory -
UseDependency.register(InstanceBuilder<
T> builder, {DependencyMode mode = DependencyMode.builder, String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/without id. -
UseDependency.singleton(InstanceBuilder<
T> builder, {String? id, String? debugLabel}) -
Register a
builderfunction of theTdependency with/withoutidas DependencyMode.singleton and creates the instance if it isn't already registered, else gets its instance only.factory
Properties
-
$
→ HookBindingZone<
IHook> -
This variable is used to register
IHookand attach theIStatethat are defined here.final - boundInstance → Object?
-
The reference instance to the current state.
no setterinherited
-
debugInfo
→ Map<
String, dynamic> -
A map containing information about state for debugging purposes.
no setter
- debugLabel → String?
-
A label used for debugging purposes.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String?
-
It's used to identify the instance of
Tdependency.final - instance → T?
-
Returns the instance if found the dependency,
or
nullif the dependency is not found it or has not been created yet.no setter - isDisposed → bool
-
Returns
trueif the state has been disposed.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
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.
-
initHook(
) → void -
Initializes the hook.
This method is called when the hook is created.
You can override this method to ensure that the hook is properly
initialized and to bind the instance to the states.
This is particularly useful for setting up state dependencies or
performing side effects when the hook is first created.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notify(
) → 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 dynamic fnUpdate()?]) → void -
Executes
fnUpdate, and notify the listeners about to update.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited