route_life 0.0.2 copy "route_life: ^0.0.2" to clipboard
route_life: ^0.0.2 copied to clipboard

outdated

A new Flutter project.

if you wan to listen route lifecycle in widget, this is a way.

Usage #

1.set navigatorObservers

RouteLifeObserver routeLifeObserver = RouteLifeObserver();

MaterialApp(
      navigatorObservers: [
        routeLifeObserver
      ],
    );
  1. with RouteLifeMixin or AppLifeMixin
class _GamePageState extends State<GamePage> with RouteLifeMixin,AppLifeMixin{
  @override
  void initState() {
    super.initState();
    _playGamePageMusic();
  }

  @override
  void dispose() {
    _stopGamePageMusic();
    super.dispose();
  }

  @override
  void onRoutePause(Route nextRoute) {
    _pauseGamePageMusic();
  }

  @override
  void onRouteResume(Route nextRoute) {
    _resumeGamePageMusic();
  }

  @override
  void onAppLifeChanged(bool resume) {
    if(!isRouteShowing){
      return;
    }
    if(resume){
      _resumeGamePageMusic();
    }else{
      _pauseGamePageMusic();
    }
  }
}
1
likes
0
pub points
28%
popularity

Publisher

unverified uploader

A new Flutter project.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on route_life