我正在尝试检测用户是否已注销并将其重定向到登录页面。以下是我的方法:
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
小部件,因为父部件包含应用栏和浮动按钮,而登录视图需要在没有这些控件的情况下显示...我需要导航。
这可行吗?