设置提供程序并导航到另一个页面时出现错误

时间:2020-09-09 22:45:13

标签: flutter dart

在按钮onPressed方法中,我试图从提供程序中清除变量,然后转到另一页。

Provider.of<MyProvider>(context, listen: false).clearSomeVar());
Navigator.of(context).pushNamedAndRemoveUntil('/anotherRoute', (route) => false);

在构建器中同一页面上的其他小部件中,我具有以下内容:

if (someVar == null) {
  Navigator.of(context).pushNamedAndRemoveUntil('/coolPage', (route) => false);
  return Container();
}```

The screen goes red for a second, and I get the following error:

> setState() or markNeedsBuild() called during build.

0 个答案:

没有答案