所有的问题都解决了。
将观察者从小部件树(materialappwidget)的根放置在导航器上。
如果您需要更多说明,请访问此链接:https : //api.flutter.dev/flutter/widgets/RouteObserver-
class.html
我已经在我的项目中实现了它,并且工作得很好@ Sp4Rx
// Register the RouteObserver as a navigation observer.final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>(); void main() {runApp(MaterialApp(home: Container(),navigatorObservers: [routeObserver], )); } class RouteAwareWidget extends StatefulWidget { State<RouteAwareWidget> createState() => RouteAwareWidgetState(); } // Implement RouteAware in a widget's state and subscribe it to the RouteObserver. class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware {@overridevoid didChangeDependencies() { super.didChangeDependencies();routeObserver.subscribe(this, ModalRoute.of(context));}@overridevoid dispose() {routeObserver.unsubscribe(this);super.dispose();}@overridevoid didPush() { // Route was pushed onto navigator and is now topmost route.} @overridevoid didPopNext() { // Covering route was popped off the navigator. }@overrideWidget build(BuildContext context) => Container(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)