route_lifecycle

a new way to manage routes lifecycle.

Route路由生命周期管理插件

install

Add to pubspec

the latest version is pub package

dependencies:
  route_lifecycle: $latest_version

import in dart code

import 'package:route_lifecycle/route_lifecycle.dart';

Usage


/// config navigatorObservers

MaterialApp(
      navigatorObservers: [
        ...
        RouteMixin.getRouteLifecycleObserver(),
      ],
    );


/// with RouteMixin<T> 

class _HomePageState extends State<HomePage> with RouteMixin<HomePage> {
  @override
  String getRouteName() {
    return "/main";
  }

  @override
  void init() {
    super.init();
  }

  @override
  void resume() {
    super.resume();
  }

  @override
  void stop() {
    super.stop();
  }

  @override
  void inactive() {
    super.inactive();
  }
}