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:

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

See also:

  • DependencyInjection, a dependency manager.
  • UseEffect, a side-effect manager.
Inheritance

Constructors

UseDependency.new({String? id, String? debugLabel})
A RtHook that allows to manages a dependency of T with/without id.
UseDependency.builder(InstanceBuilder<T> builder, {String? id, String? debugLabel})
Register a builder function of the T dependency with/without id 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, String? debugLabel})
Register a builder function of the T 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, String? debugLabel})
Register a builder function of the T dependency with/without id as 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 T dependency with/without id.
UseDependency.lazyBuilder(InstanceBuilder<T> builder, {String? id, String? debugLabel})
Register a builder function of the T dependency with/without id as DependencyMode.builder.
factory
UseDependency.lazyFactory(InstanceBuilder<T> builder, {String? id, String? debugLabel})
Register a builder function of the T dependency with/without id as DependencyMode.factory.
factory
UseDependency.lazySingleton(InstanceBuilder<T> builder, {String? id, String? debugLabel})
Register a builder function of the T dependency with/without id as DependencyMode.singleton.
factory
UseDependency.register(InstanceBuilder<T> builder, {DependencyMode mode = DependencyMode.builder, String? id, String? debugLabel})
Register a builder function of the T dependency with/without id.
UseDependency.singleton(InstanceBuilder<T> builder, {String? id, String? debugLabel})
Register a builder function of the T dependency with/without id as 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 IHook and attach the IState that 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
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
isDisposed bool
Returns true if the state has been disposed.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateManagement → StateManagement<IState>
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