0

I want to use Snackbar with root Scaffold widget to show many messages from different places like this:

_scaffoldKey.currentState.showSnackBar(SnackBar(
  content: Text('$message'),
  backgroundColor: Colors.green,
));

But when I have some widget(e.g. another Scaffold which I can't use) which fully above my root widget, I don't see the Snackbar.

So, how can I show the Snackbar above all widgets?

konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
  • You can use the Scaffold.of(context) to find out the nearest Scaffold. Is that enough? – Darish Feb 24 '20 at 09:29
  • 1
    @Darish nope, unfortunately. I have `BlocListener` in the my root widget, necessary messages come there – konstantin_doncov Feb 24 '20 at 09:32
  • So you trigger some asynchronous action on Route A, navigate to Route B, the async action completes and you want to display a Snackbar on top of Route B? Have a look at https://stackoverflow.com/questions/60122105/flutter-modifying-scaffold-to-track-currently-displayed-scaffolds-buildcontext and modify it to use your Bloc instead of Provider – Ovidiu Feb 24 '20 at 10:14
  • @Ovidiu sorry for the long delay, I had other tasks. Thanks, but as I understand, if I show Snackbar on the route A, this solution will close the Snackbar when I go to the route B, is it correct? – konstantin_doncov Mar 06 '20 at 05:32
  • Yes, but that's how Snackbars work.. Have a look for 3rd party packages or an Overlay-based solution if the default behavior is not satisfactory. – Ovidiu Mar 06 '20 at 09:21

0 Answers0