WouterListenable<T extends Listenable> class
A widget that synchronizes a Flutter Listenable (e.g., a TabController,
PageController, or custom ChangeNotifier) with Wouter's navigation state.
WouterListenable is designed for scenarios where UI elements driven by a
Listenable (like tabs in a TabBarView or pages in a PageView) should
correspond to distinct routes in the Wouter system. It enables two-way
synchronization:
- Listenable to Wouter: When the
Listenablechanges its state (e.g., user swipes to a new tab/page),WouterListenableupdates Wouter's current route (typically using areplaceaction) to reflect this change. - Wouter to Listenable: When Wouter's route changes (e.g., due to
browser back/forward buttons, or programmatic navigation),
WouterListenableupdates the state of theListenable(e.g., changing the active tab/page).
It requires several callback functions to bridge the gap between the
Listenable's state (often represented by an index) and Wouter's path-based
routing.
The builder callback is used to construct the UI, typically passing the Listenable instance and the list of child widgets (from routes) to widgets like TabBarView or PageView.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- WouterListenable
Constructors
-
WouterListenable({Key? key, required CreateListenable<
T> create, required DisposeListenable<T> dispose, required OnGetListenableIndex<T> index, required OnRouteChanged<T> onChanged, required Map<String, Widget> routes, required WouterListenableWidgetBuilder<T> builder, required ToPathCallback toPath, required ToIndexCallback toIndex}) -
Creates a WouterListenable widget.
const
Properties
-
builder
→ WouterListenableWidgetBuilder<
T> -
A builder function that constructs the UI.
It receives the BuildContext, the Listenable instance (
T), and a list of child widgets (derived fromwidget.routes.values). This is typically used to build widgets likeTabBar+TabBarVieworPageView.final -
create
→ CreateListenable<
T> -
A function that creates the Listenable instance (
T). It receives the BuildContext and an initial index derived from the current Wouter route.final -
dispose
→ DisposeListenable<
T> -
A function to dispose of the Listenable instance when this widget
is removed from the tree.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
index
→ OnGetListenableIndex<
T> -
A function that extracts an integer index (or a similar representative value)
from the current state of the Listenable instance (
T). This index is used to determine the corresponding route.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChanged
→ OnRouteChanged<
T> -
A callback invoked when Wouter's route changes and the Listenable (
T) needs to be updated to reflect the new route (represented byint index). This function is responsible for actually changing theListenable's state.final -
routes
→ Map<
String, Widget> -
A map where keys are route path segments (relative to the WouterListenable's
position in the routing tree) and values are the Widgets to be displayed
for each corresponding state of the Listenable.
The order of
routes.values.toList()is passed to the builder.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- toIndex → ToIndexCallback
-
A callback to convert a Wouter route path back into an index for the Listenable.
It receives the
baseWouter path, the current Wouterpath, and the list of route keys fromwidget.routes.final - toPath → ToPathCallback
-
A callback to convert an index (from the Listenable) into a full
Wouter route path.
It receives the
index, thebaseWouter path, the current Wouterpath, and the list of route keys fromwidget.routes.final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< WouterListenable< 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