Display SnackBar in Flutter

In my case i had code like this (in class state) final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); void showInSnackBar(String value) { _scaffoldKey.currentState.showSnackBar(new SnackBar(content: new Text(value))); } but i didn’t setup the key for scaffold. so when i add key: _scaffoldKey @override Widget build(BuildContext context) { return new Scaffold( key: _scaffoldKey, body: new SafeArea( snackbar start … Read more

Scaffold.of() called with a context that does not contain a Scaffold

This exception happens because you are using the context of the widget that instantiated Scaffold. Not the context of a child of Scaffold. You can solve this by just using a different context : Scaffold( appBar: AppBar( title: Text(‘SnackBar Playground’), ), body: Builder( builder: (context) => Center( child: RaisedButton( color: Colors.pink, textColor: Colors.white, onPressed: () … Read more