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