-
-
Save shivanchalaeologic/c6dce39ba4eb8a46ca819806e113fdd6 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'; | |
import 'package:flutter_route_obser/main.dart'; | |
class RouteAwareWidget extends StatefulWidget { | |
final String name; | |
final Widget child; | |
RouteAwareWidget(this.name, {@required this.child}); | |
@override | |
State<RouteAwareWidget> createState() => RouteAwareWidgetState(); | |
} | |
class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware { | |
@override | |
void didChangeDependencies() { | |
super.didChangeDependencies(); | |
routeObserver.subscribe(this, ModalRoute.of(context)); | |
} | |
@override | |
void dispose() { | |
routeObserver.unsubscribe(this); | |
super.dispose(); | |
} | |
@override | |
// Called when the current route has been pushed. | |
void didPush() { | |
print('didPush ${widget.name}'); | |
} | |
@override | |
// Called when the top route has been popped off, and the current route shows up. | |
void didPopNext() { | |
print('didPopNext ${widget.name}'); | |
} | |
@override | |
Widget build(BuildContext context) => widget.child; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment