From d0b9720bfa001fb499d381bbecae2facbf0bcb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Fri, 30 Apr 2021 17:24:19 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0homepage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home_page/home_page.dart | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index e6b76f3..cb0c5ed 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -492,3 +492,46 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker } } } + +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(); +} \ No newline at end of file