小编Tah*_*lam的帖子

使用 go_router 和 flutter_bloc 以及 Auth 和 UnAuth 流程进行反应式重定向

使用 flutter_bloc 和 go_router 实现基于身份验证更改的导航。

我需要做的是,如果用户经过身份验证,则应将其重定向到主屏幕,并能够导航身份验证流程...(HomeScreen,TestScreen1,TestScreen2)

如果用户在任何时候未经身份验证,则应将其重定向到登录屏幕,如果未知,则应重定向到启动屏幕。

我已经解决了许多 stackoverflow 问题和 github 问题,但没有一个提供我们如何实现这一目标的最佳实践。

问题:

  • 无法在身份验证流程中导航,HomeScreen -> Test1 || 主屏幕 -> 测试 2

提供以下资产:

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)

flutter flutter-navigation flutter-bloc flutter-go-router

6
推荐指数
1
解决办法
3071
查看次数