Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how to use flushbar #116

Closed
degloff opened this issue Mar 18, 2020 · 1 comment
Closed

Unclear how to use flushbar #116

degloff opened this issue Mar 18, 2020 · 1 comment

Comments

@degloff
Copy link

degloff commented Mar 18, 2020

I am trying to use flushbar for all kinds of notifications. it works well in general. However I face this error that I do not properly understand. It may well be a wrong usage of flushbar.

Assume I have a widget that gets a list of data. During build I want to notify the user why for example the data is empty (based on his search selection). The simple minded approach is to do something like this (I tried the naviatgor approach because the show method also did not work):

@override
  Widget build(BuildContext context) {
    if (data.isEmpty) {
      var flushbar = FlushbarHelper.createInformation(message: 'No data matching selection criteria.');
      Navigator.push(context, FlushbarRoute(theme: Theme.of(context), flushbar: flushbar));
      return Container(
          height: 100,
          child: Center(
            child: Icon(Icons.crop_square, size: 35),
          )
      );
    } else {
      return GFItemsCarousel(
          rowCount: 2,
          children: data.map((d) {
            return overviewTile(context, d);
          }).toList()
      );
    }
  }

I get the following exception

The following assertion was thrown building FilteredGameCarousel(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#0ea56], _InheritedTheme]):
setState() or markNeedsBuild() called during build.

This Overlay 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: Overlay-[LabeledGlobalKey<OverlayState>#dca70]

What is the cause of that? Is it a wrong usage?

@degloff degloff changed the title Unclear how to use flushbar Unclear how to use flushbar Mar 18, 2020
@degloff
Copy link
Author

degloff commented Mar 19, 2020

Seems to work if I wrap it with WidgetsBinding.instance.addPostFrameCallback

@degloff degloff closed this as completed Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant