我试图检测用户不再经过身份验证,并将用户重定向到登录.我就是这么做的
Widget build(BuildContext context) {
return FutureBuilder(
future: _getData(context),
builder: (context, snapshot) {
try {
if (snapshot.hasError && _isAuthenticationError(snapshot.error)) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LoginView()));
}
不幸的是,在构建时进行导航是不起作用的.它会抛出此错误
flutter: setState() or markNeedsBuild() called during build.
flutter: This Overlay widget cannot be marked as needing to build because the framework is already in the
flutter: process of building widgets. A widget can be marked as needing to be built during the build
我不能只返回LoginView
个小部件,因为父小部件包含应用程序栏和浮动按钮,登录视图需要在没有这些控件的情况下显示..我需要导航.
有可能吗?