*what is the BuildContext object/context?*
Before we knowing about BuildCotext, We have to know about the Element object.
**What is Element object**
*(note: As a flutter developer we never worked with Element object, but we worked with an object(known as BuildContext object) that's similar to Element object)*
> The Element object is the **build location** of the current widget.
**What's really mean by "build location" ?**
>1. when the framework builds a widget object by calling its constructor will correspondingly need to create an element object for that widget object.
>2. And this element object represents the build location of that widget.
>3. This element object has many useful instance methods.
**Who uses the Element object and its methods ?**
> They are 02 parties that use the Element object and its methods.
> 1. Framework (To create RenderObject tree etc)
> 2. Developers (Like us)
**What is BuildContext object ?**
> BuildContext objects are actually Element objects. The BuildContext interface is used to discourage direct manipulation of Element objects.
So `BuildContext object = discouraged element object` (That contains less number of instance methods compared to the original Element object)
**Why framework discouraged the Element object and pass it to us ?**
> Because Element object has instance methods that must only be needed by the framework itself.
> but what happens when we access these methods by us, It's something that should not be done.
> So that the reason why framework discouraged the Element object and pass it to us
----------------------------------------------------
----------------------------------------------------
***Ok Now let's talk about the topic***
**What does BuildContext object do in Flutter ?**
> BuildContext object has several useful methods to easily perform certain tasks that need to be done in the widget tree.
1. findAncestorWidgetOfExactType<T>().
> Returns the nearest ancestor widget of the given type T.
2. findAncestorStateOfType<T>().
> Returns the State object of the nearest ancestor StatefulWidget.
3. dependOnInheritedWidgetOfExactType<T>().
> Obtains the nearest widget of the given type T, which must be the type of a concrete InheritedWidget subclass, and registers this build context with that widget such that when that widget changes.
[Used by Provider package]
The above methods are mostly used instance methods of BuildContext object if you want to see all the methods of that BuildContext object visit this [LINK][1] + see @remi Rousselot's answer.
[1]:
[To see links please register here]