Flutter Show Snackbar внутри сборки - PullRequest
0 голосов
/ 29 мая 2020

Я реализовал шаблон BLo C в своем приложении, потому что у меня возникла проблема.

Если у меня есть особое событие, мне нужно показать закусочную, но у меня есть эта ошибка:

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);

1 Ответ

2 голосов
/ 29 мая 2020

Попробуйте shownackbar в blo c listener и убедитесь, что blo c listener определен в scaffold.

...