Understanding BuildContext
Published in
6 min readApr 11, 2020
In Material Design, when we want to give some subtle feedback to the user, we may be inclined to use a SnackBar:
If we are using a Scaffold
in our screens, we can easily show it by using the showSnackBar
method with a button in the body:
But if we click on the button, no SnackBar
is displayed, and we get the following error:
We now have two possible solutions:
- Don’t read the error message and try to fix it any way;
- Read the error message and try to fix it and understand why this happens;
Following the first route, we may be inclined to access the showSnackbar
method, which resides in the ScaffoldState
, with a GlobalKey
: