使用 flutter_bloc 和 go_router 实现基于身份验证更改的导航。
我需要做的是,如果用户经过身份验证,则应将其重定向到主屏幕,并能够导航身份验证流程...(HomeScreen,TestScreen1,TestScreen2)
如果用户在任何时候未经身份验证,则应将其重定向到登录屏幕,如果未知,则应重定向到启动屏幕。
我已经解决了许多 stackoverflow 问题和 github 问题,但没有一个提供我们如何实现这一目标的最佳实践。
问题:
提供以下资产:
Tried to listen to a value exposed with provider, from outside of the widget tree.
This is likely caused by an event handler (like a button's onPressed) that called
Provider.of without passing `listen: false`.
To fix, write:
Provider.of<$T>(context, listen: false);
It is unsupported because may pointlessly rebuild the widget associated to the
event handler, when the widget tree …Run Code Online (Sandbox Code Playgroud)