diff --git a/example/lib/main.dart b/example/lib/main.dart index 2ac910c..ad8f824 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -112,7 +112,7 @@ class _MyAppState extends State { child: child, ); }, - navigatorObservers: [lifeObserver], + // navigatorObservers: [lifeObserver], theme: ThemeData( fontFamily: 'PingFang', primaryColor: HexColor.fromHex('#FF4242'), diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 457cc39..fe8bd14 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -51,7 +51,7 @@ class HomePage extends StatefulWidget { _HomePageState createState() => _HomePageState(); } -class _HomePageState extends LifeState with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { +class _HomePageState extends State with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { int _currentIndex = 0; List> _data = List(); static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER'); @@ -453,46 +453,3 @@ class _HomePageState extends LifeState with WidgetsBindingObserver, Ti // TODO: implement wantKeepAlive bool get wantKeepAlive => true; } - -final RouteObserver lifeObserver = RouteObserver(); - -abstract class LifeState extends State with RouteAware { - @override - void initState() { - super.initState(); - } - - @override - void didChangeDependencies() { - lifeObserver.subscribe(this, ModalRoute.of(context)); - super.didChangeDependencies(); - } - - @override - void dispose() { - lifeObserver.unsubscribe(this); - super.dispose(); - } - - void didPop() { - onPaused(); - } - - void didPopNext() { - onResume(); - print("回到首页"); - setState(() {}); - } - - void didPush() { - onResume(); - } - - void didPushNext() { - onPaused(); - } - - void onResume(); - - void onPaused(); -}