ZenView<T extends ZenController> class
abstract
Base class for screens and pages that own a ZenController.
Controller Resolution
When the widget mounts, ZenView resolves its controller in this order:
- Nearest ZenScope in the widget tree (scope-isolated; safe for multiple simultaneous instances).
- Global Zen DI — for singleton screens registered at the app root.
If neither source has the controller and createController is provided, the controller is created and registered automatically into the nearest scope (or global DI if no scope ancestor is present).
Usage
Override build and use the controller getter to access the resolved controller — always non-nullable inside build.
class CounterPage extends ZenView<CounterController> {
const CounterPage({super.key});
@override
CounterController Function()? get createController =>
() => CounterController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: ZenObserver(() => Text('${controller.count.value}')),
floatingActionButton: FloatingActionButton(
onPressed: controller.increment,
child: const Icon(Icons.add),
),
);
}
}
Multi-Instance Safety
ZenView uses a per-instance stack registry. When two widgets of the same
type are active simultaneously (e.g., nested navigation, split-screen), each
pushes its own controller onto the stack. The controller getter always
returns the innermost (most recently mounted) instance — mirroring how
Flutter's InheritedWidget lookup works.
For components that need guaranteed per-widget isolation, use a plain
StatelessWidget and context.controller<T>() directly — this resolves
purely from ZenScope, with no global registry involved.
See also:
- ZenScopeWidget — to provide an isolated ZenScope to a subtree.
- ZenBuilder — for precise, builder-pattern reactive rebuilds.
- ZenObserver — for automatic reactive dependency tracking.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ZenView
- Available extensions
Properties
- controller → T
-
Available on ZenView<
T> , provided by the ZenViewExtension extensionno setter - createController → T Function()?
-
Optional factory to create the controller if it is not already registered.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scope → ZenScope?
-
Optional explicit scope override.
no setter
- tag → String?
-
Optional tag for disambiguating multiple registrations of the same type.
no setter
Methods
-
build(
BuildContext context) → Widget - Build the widget.
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ZenView< T> > -
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