Use Widget State | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/13739693-your-first-flutter-app/lessons/8

Hi, whats is BuildContext and how I know that I have to pass this? When do I need a context?

Hi @gisesonia, thanks for the question! The BuildContext is a handle to where you are in the widget tree. You pass it to widget builder methods, such as overrides of the build() method. When getting started with Flutter, thatโ€™s the main place where youโ€™ll see it.

You also will use it when calling of methods, like when showing a Snackbar using something like Scaffold.of(context).showSnackBar(...). You can access the context within build methods, and also get it from the State.context member property.

Thank you. I will look for more examples.