AmplitudeNavigatorObserver class
A NavigatorObserver that autocaptures Flutter screen views as
[Amplitude] Screen Viewed events.
A Flutter app runs inside a single native surface (one FlutterViewController
on iOS, one FlutterActivity on Android), so the native SDKs' screenViews
autocapture cannot observe Flutter route navigation. Attach this observer to
your app's Navigator.observers to autocapture screen views on every
platform, including web.
Capture is gated on the screenViews autocapture option of the Amplitude
instance passed in — if screen views are disabled the observer is a no-op.
Both attaching the observer AND enabling screenViews are required (Flutter
cannot inject a NavigatorObserver automatically).
The observer tracks Flutter route changes on every platform, including web.
This matters on web because a Flutter route change does not necessarily
change the browser URL, so route-only navigations would be missed by the
Browser SDK's URL-based pageViews autocapture.
On web, pageViews and this observer are independent. If you enable both, a
navigation that also changes the URL is captured as both
[Amplitude] Page Viewed and [Amplitude] Screen Viewed. To record a single
navigation event, disable the one you don't want — typically
pageViews: PageViewsDisabled() so the observer's route-based
[Amplitude] Screen Viewed is authoritative (keep pageUrlEnrichment
enabled to retain page-URL properties on the emitted events).
Screen names come from RouteSettings.name by default, so routes must be
named — via named routes, RouteSettings(name: ...), or a router such as
go_router — to be captured. Routes with no name are skipped (with a debug-mode
log). Provide a custom nameExtractor to derive names another way.
final analytics = Amplitude(Configuration(
apiKey: 'API_KEY',
autocapture: AutocaptureOptions(screenViews: true),
));
MaterialApp(
navigatorObservers: [AmplitudeNavigatorObserver(analytics)],
// ...
);
- Inheritance
-
- Object
- NavigatorObserver
- AmplitudeNavigatorObserver
Constructors
Properties
- amplitude → Amplitude
-
The Amplitude instance screen view events are tracked with.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- nameExtractor → ScreenNameExtractor
-
Derives the screen name reported for a route.
final
-
The navigator that the observer is observing, if any.
no setterinherited
- routeFilter → bool Function(Route? route)
-
Decides whether a route should be tracked as a screen.
final
- 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.
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
oldRoutewithnewRoute.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