MorphNavigatorObserver class

Drop-in NavigatorObserver that feeds Morph's behavior store with every route transition. Plug it into any router that accepts a NavigatorObserver:

// GoRouter
GoRouter(
  observers: [MorphNavigatorObserver.instance],
  routes: [...],
)

// Vanilla MaterialApp
MaterialApp(
  navigatorObservers: [MorphNavigatorObserver.instance],
  routes: {...},
)

The observer is a singleton — MorphProvider auto-attaches its internal BehaviorDB at boot, so the dev never has to wire that part manually. Routes without a name (or with an empty one) are ignored — nothing useful to report on anonymous routes.

Each transition records: • trackSequence(from, to) — the from → to pair for sequence mining • trackClick(to, 'navigation') — counts the destination as a visit • trackTimeSpent(from, ms) — accumulates dwell time on the previous page when the user navigates away

The observer also keeps an in-memory sessionHistory (the route names visited in order, this session) — read it from AnalyticsReporter._buildPayload to compute average navigation depth.

Inheritance

Constructors

MorphNavigatorObserver()
Public so tests can build their own instance with a stubbed BehaviorDB.

Properties

currentRoute → String?
Name of the route the user is currently on, or null when the observer has never seen a transition (boot before first push). Same as sessionHistory.last when populated; provided as a getter so callers can read it without bothering with bounds checks.
no setter
hashCode → int
The hash code for this object.
no setterinherited
The navigator that the observer is observing, if any.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sessionHistory → List<String>
Ordered list of route names visited this session — front of the list is the entry route, back is the current route. Reset on detach (i.e. app dispose). Read by AnalyticsReporter for navigation-depth metrics.
final

Methods

attach(BehaviorDB db) → void
Wired by MorphProvider once the local store is initialized. Safe to call multiple times — subsequent attaches replace the ref (handy for hot reload scenarios).
detach() → void
Called by MorphProvider on dispose so the observer doesn't keep a dangling reference to a closed Hive store.
didChangeTop(Route topRoute, Route? previousTopRoute) → void
The top most route has changed.
inherited
didPop(Route route, Route? previousRoute) → void
The Navigator popped route.
override
didPush(Route route, Route? previousRoute) → void
The Navigator pushed route.
override
didRemove(Route route, Route? previousRoute) → void
The Navigator removed route.
inherited
didReplace({Route? newRoute, Route? oldRoute}) → void
The Navigator replaced oldRoute with newRoute.
override
didStartUserGesture(Route route, Route? previousRoute) → void
The Navigator's routes are being moved by a user gesture.
inherited
didStopUserGesture() → void
User gesture is no longer controlling the Navigator.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

instance → MorphNavigatorObserver
Process-wide singleton. MorphProvider calls attach on it during bootstrap and detach on dispose. Apps can pass this same instance to multiple routers (e.g. nested navigators) without issue.
final