-
-
Save shivanchalaeologic/3ded41042244c9b1c714863a9b8d3367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class MyRouteObserver extends RouteObserver<PageRoute<dynamic>> { | |
void _sendScreenView(PageRoute<dynamic> route) { | |
var screenName = route.settings.name; | |
print('screenName $screenName'); | |
// do something with it, ie. send it to your analytics service collector | |
} | |
@override | |
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { | |
super.didPush(route, previousRoute); | |
if (route is PageRoute) { | |
_sendScreenView(route); | |
} | |
} | |
@override | |
void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) { | |
super.didReplace(newRoute: newRoute, oldRoute: oldRoute); | |
if (newRoute is PageRoute) { | |
_sendScreenView(newRoute); | |
} | |
} | |
@override | |
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) { | |
super.didPop(route, previousRoute); | |
if (previousRoute is PageRoute && route is PageRoute) { | |
_sendScreenView(previousRoute); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment