flutter_lean_di library

Classes

Alias<TAlias extends Object, TTarget extends TAlias>
Registers the exact same instance created by a TTarget dependency under an additional key TAlias - typically a superclass or an interface TTarget implements - so it can also be looked up as TAlias: deps.get<TAlias>() and deps.get<TTarget>() return the identical object.
ChangeNotifierDependency<T extends ChangeNotifier>
A ListenableDependency specialized for ChangeNotifier: unlike the base class, this defaults dispose to calling value.dispose(), since every ChangeNotifier supports that.
Dependency<T extends Object>
An immutable object describing a dependency. It can be registered in Deps by using Deps.add.
DependencyChanged
Event emitted by Deps when a dependency value is changed, i.e. as a result of the Dependency.create callback (re-)running.
DependencyDiagnostics
A snapshot of a single registered dependency's descriptor and current resolution state, for inspection/diagnostics only - see Deps.debugOwnDependencies, which is what flutter_lean_di's diagnostics extensions build on to show a Deps hierarchy.
DependencyObserver<T extends Object>
Observes internal state changes of an already-resolved dependency value - e.g. a wrapped ChangeNotifier/Listenable firing its own notifications
DependencyRegistered
Event emitted by Deps when a dependency is registered. Dependencies are created lazily, so its value may not exist yet - once Dependency.create runs, it will be followed by a DependencyChanged event.
DependencyUnregistered
Event emitted by Deps when a dependency is unregistered.
Deps
A box that contains dependencies. Deps can also form a tree-like hierarchy to allow for scoping and overriding dependencies. Reading values from a deps object that it doesn't contain but its ancestors will return the value from the nearest ancestor.
DepsEvent
Event emitted by Deps when a dependency is registered, unregistered, or changed.
DepsProvider
Register on mount; Unregister on unmount.
DepsReader
Passed to Dependency.create instead of a plain Deps - reads made through it are how a dependency declares what it reacts to, instead of a separate, easy-to-forget list.
ListenableDependency<T extends Listenable>
A Dependency whose value is a Listenable - deps.watch<T>() (and context.watch<T>()) reacts to T calling notifyListeners(), not just to a new instance being registered. Not every Listenable is disposable, so unlike ChangeNotifierDependency this has no default dispose.
ListenableDependencyObserver<T extends Listenable>
The DependencyObserver behind ListenableDependency - relays listenable's own notifications to Deps.watch subscribers.
Module
Groups several Dependency descriptors so they can be registered and removed together as one unit - see Deps.add/Deps.addAll and Deps.remove, which also accepts a Module to remove every dependency it lists. DependencyDiagnostics.module reports which Module (if any) a given registered dependency came from.
Registerable
Something that can be passed to Deps.add/Deps.addAll (and removed via Deps.remove) - implemented by Dependency and Module.

Extensions

DepsContext on BuildContext
Shortcuts for obtaining Deps values from BuildContext.
DepsDiagnosticsTree on Deps
Turns a Deps scope into something Flutter's diagnostics tooling can display - the widget inspector, debugDumpApp()-style tools, or just debugPrint(deps.toDiagnosticsNode().toStringDeep()) for a quick dump from anywhere.
DepsWatchMany on Deps
Deps.watchInstance-based helpers for watching several dependencies at once - watch2 through watch5 cover the common fixed-arity cases; watchMany is the general, dynamic-arity version they're built on.

Constants

leanDiDiagnosticsMode → const bool
Enables tracking of a Deps scope's child scopes (created via Deps.fork) purely for inspection - see Deps.debugChildren, and flutter_lean_di's diagnostics extensions for viewing a whole hierarchy.

Typedefs

DependencyKey = Type
The identifier a Dependency is registered and looked up by - its runtime Type, by default T itself (see Dependency.key).
DependencyObserverFactory<T extends Object> = DependencyObserver<T>? Function(T value)
A factory function to create a DependencyObserver for a dependency.
Selector<T, R> = R Function(T value)
Derives an R from a resolved T value - see DepsContext.select.
Unregister = void Function()
Callback to unregister a dependency. It will be disposed of automatically.

Exceptions / Errors

DependencyCycleError
Thrown when resolving key re-enters its own Dependency.create before the first call has finished - i.e. a dependency, directly or indirectly, depends on itself.
DependencyNotRegisteredError
Thrown by Deps.get and Deps.tryGet when no dependency is registered under key in this Deps scope or any of its ancestors.
DepsDisposedError
Thrown when an operation needs this Deps scope to still be alive, but Deps.dispose has already been called on it - by Deps.add (adding to a disposed scope makes no sense) and by Deps.get/Deps.tryGet (resolving a value from a scope whose dependencies have all been torn down doesn't either).