使用 flutter_phoenix
使用方法
void main() {
runApp(
Phoenix( child: App(), ),
);
}
触发:Phoenix.rebirth(context);
坑:
如果使用了MaterialApp,不能设置 navigatorKey
如需获取全局context 使用navigatorObservers
class CustomNavigatorObserverextends NavigatorObserver{
static CustomNavigatorObserver_instance;
static CustomNavigatorObservergetInstance() {
if (_instance ==null) {
_instance =CustomNavigatorObserver();
}
return _instance;
}
}
MaterialApp(
...
navigatorObservers: [CustomNavigatorObserver()],
...
)
CustomNavigatorObserver.getInstance().navigator.pushNamed('/login');