What about if you create key for the screen Scaffold like this (put this object inside the screen state class):
final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
and then set this variable to the Scaffold key like this:
return new Scaffold(
key: scaffoldKey,
appBar: new AppBar(
.......,
),
and at the end to show the SnackBar just use somewhere inside the screen state class this code :
scaffoldKey.currentState
.showSnackBar(new SnackBar(content: new Text("Hello")));
or you can wrap the latest code in method like this :
void showInSnackBar(String value) {
scaffoldKey.currentState
.showSnackBar(new SnackBar(content: new Text(value)));}
and then just call this method and pass the snack bar message inside.
If you want to show the snack bar message on the next screen, after you navigate away from the initial context, just call the snack bar method on the next screen, not on the first screen.
Hope this will help
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…