0

我有问题在我的应用程序中实现了 BLoC 模式。

一旦我有一个特殊的事件,我需要显示一个小吃店,但我有这个错误:

The following assertion was thrown building InteractWithMorceauPage(dirty, dependencies: [MediaQuery], state: _InteractWithMorceauPageState#25201):
setState() or markNeedsBuild() called during build.

This Scaffold widget cannot be marked as needing to build because the framework is already in the process of building widgets.  A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: Scaffold
  dependencies: [TickerMode, MediaQuery, _InheritedTheme, _LocalizationsScope-[GlobalKey#dc380], Directionality]
  state: ScaffoldState#8a46b(tickers: tracking 3 tickers)
The widget which was currently being built when the offending call was made was: InteractWithMorceauPage
  dirty
  dependencies: [MediaQuery]
  state: _InteractWithMorceauPageState#25201

这是我正在做的事情:

   else if (widget.state is TickNotPossibleState){
      buttonState = PAUSE;
      Scaffold.of(context).showSnackBar(SnackBar(content: Text("My Snackbar text!")));
    }

    return _generatePage(buttonState);
4

1 回答 1

3

尝试在 bloc 侦听器中显示 nackbar 并确保 bloc 侦听器在脚手架下定义。

于 2020-05-29T01:11:00.850 回答