-1

why we pass context when we are navigating to next screen in flutter?

And what context really is? Why we need context?

  • 3
    Does this answer your question? [What does "context" of "Widget build(BuildContext context)" mean in Flutter?](https://stackoverflow.com/questions/54480937/what-does-context-of-widget-buildbuildcontext-context-mean-in-flutter) – Tomer Shetah Oct 04 '20 at 07:45
  • Nope this is not the answer to my question – M Sarmad Qadeer Oct 04 '20 at 09:40
  • Does this answer your question? [What does BuildContext do in Flutter?](https://stackoverflow.com/questions/49100196/what-does-buildcontext-do-in-flutter) – Christopher Moore Oct 09 '20 at 16:40

1 Answers1

0

The BuildContext in Flutter is an object that holds information about the context the Widget is in. Most importantly it holds where in the Widget-tree our Widget is located. This is why we need the BuildContext to get a certain Provider, ThemeData or MediaQuery for instance.

var media = MediaQuery.of(context);

Without the BuildContext belonging to the Widget we are in, Flutter has no way of knowing WHERE (in the Widget-tree) to look for the Data we are looking for.

Same goes for Navigation, we need to know where we are coming from, to go somewhere new.

Benedikt J Schlegel
  • 1,707
  • 1
  • 10
  • 23