From 3742c0d4ed707e8621784fdb66482544530c18df Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Sat, 17 Apr 2021 11:45:50 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=99=BA=E8=83=BD=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E9=99=A4=E4=BA=86=E5=88=86=E4=BA=AB=E9=A1=B5=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 2 +- lib/pages/home_page/home_page.dart | 45 +----------------------------- 2 files changed, 2 insertions(+), 45 deletions(-) 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(); -}