LDNavigatorObserver class

A NavigatorObserver that reports Flutter route changes to LaunchDarkly observability as screen views.

Flutter renders into a single native Activity/UIViewController, so the native SDK's automatic screen detection never sees Flutter route changes. Attaching this observer bridges that gap: each navigation is forwarded to LDObserve.trackScreenView, which emits a screen_view span and a Session Replay Navigate timeline event.

Add it to your top-level navigator:

MaterialApp(
  navigatorObservers: [LDNavigatorObserver()],
  // ...
);

By default the screen name is taken from route.settings.name minus its query string; routes without a name are skipped. Provide screenNameExtractor to customize this (for example to derive a name from route.settings.arguments or to name otherwise-anonymous routes), or LDRoutePatterns.extractor to report the route patterns of a router that navigates by URL.

Observers are per-Navigator and a single instance cannot be shared, so an app with nested navigators (tab shells, or a Navigator inside a page) needs a separate instance for each. Routers that build their own navigator (MaterialApp.router with go_router and friends) do not accept navigatorObservers; pass the observer to the router's own observer list instead. Navigation that does not change the route stack — switching tabs in an IndexedStack, paging a PageView — is invisible to any observer and needs an explicit LDObserve.trackScreenView.

Inheritance

Constructors

LDNavigatorObserver({LDScreenNameExtractor screenNameExtractor = defaultScreenNameExtractor, String? category})
Creates an observer.

Properties

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

Methods

didChangeTop(Route topRoute, Route? previousTopRoute) → void
The top most route has changed.
override
didPop(Route route, Route? previousRoute) → void
The Navigator popped route.
inherited
didPush(Route route, Route? previousRoute) → void
The Navigator pushed route.
inherited
didRemove(Route route, Route? previousRoute) → void
The Navigator removed route.
inherited
didReplace({Route? newRoute, Route? oldRoute}) → void
The Navigator replaced oldRoute with newRoute.
inherited
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 Methods

defaultScreenNameExtractor(Route route) → String?
Default extractor: the route's RouteSettings.name, without its query string or fragment.