Created
February 12, 2019 18:26
-
-
Save marcinOz/71432c248322184ea0ed7f72932d4720 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>(); | |
class RouteAwareWidget extends StatefulWidget { | |
final Widget child; | |
RouteAwareWidget({this.child}); | |
State<RouteAwareWidget> createState() => RouteAwareWidgetState(child: child); | |
} | |
class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware { | |
final Widget child; | |
RouteAwareWidgetState({this.child}); | |
@override | |
void didChangeDependencies() { | |
super.didChangeDependencies(); | |
routeObserver.subscribe(this, ModalRoute.of(context)); | |
} | |
@override | |
void dispose() { | |
routeObserver.unsubscribe(this); | |
super.dispose(); | |
} | |
@override | |
void didPush() { | |
// Route was pushed onto navigator and is now topmost route. | |
} | |
@override | |
void didPopNext() { | |
// Covering route was popped off the navigator. | |
StoreProvider.of<AppState>(context).dispatch(NavigatePopAction()); | |
} | |
@override | |
Widget build(BuildContext context) => Container(child: child); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment