ZenRoute class

Route-scoped dependency injection widget

ZenRoute creates a new ZenScope, initializes a ZenModule with its dependencies, and provides the scope to its child widget tree via InheritedWidget.

Architecture:

  • Automatic parent scope discovery via widget tree (InheritedWidget)
  • Module-based dependency registration with dependency chaining
  • Automatic lifecycle management (init → onInit → dispose → onDispose)
  • Clean disposal when widget is removed from tree

Features:

  • Widget tree-based hierarchy: No global state, uses InheritedWidget for parent discovery
  • Module composition: Modules can declare dependencies on other modules
  • Async initialization: Supports async onInit() for setup tasks
  • Error handling: Shows error UI with retry button
  • Loading state: Displays loading UI during initialization

Example:

ZenRoute(
  moduleBuilder: () => FeatureModule(),
  page: FeaturePage(),
  scopeName: 'FeatureScope', // Optional name for debugging
)

The scope is automatically disposed when this widget is removed from the tree.

Inheritance

Constructors

ZenRoute({Key? key, required ZenModule moduleBuilder(), required Widget page, String? scopeName, Widget onError(Object error)?, Widget? loadingWidget, ZenScope? parentScope})
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingWidget Widget?
Custom loading widget shown during module initialization
final
moduleBuilder ZenModule Function()
Factory function that creates the module instance
final
onError Widget Function(Object error)?
Custom error handler for module initialization failures
final
page Widget
The main content widget that will receive the initialized scope
final
parentScope ZenScope?
Optional explicit parent scope (overrides automatic discovery) Use this when the widget tree structure doesn't match the logical scope hierarchy (e.g., navigating across different navigator stacks or detached routes).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scopeName String?
Optional name for the created scope (useful for debugging)
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<ZenRoute>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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