|
|
@@ -492,3 +492,46 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
final RouteObserver<Route> lifeObserver = RouteObserver(); |
|
|
|
|
|
|
|
abstract class LifeState<T extends StatefulWidget> extends State<T> 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(); |
|
|
|
} |