Please explain in Russian what BuildContext is. I read the documentation, but I could not understand. I also read here and in the end I did not understand any more.

    2 answers 2

    BuildContext is the context in which the current widget is created. Flutter has all the widgets.

    In Flutter, everything is a widget.

    And each widget has its own BuildContext , which will be the parent by calling the StatelessWidget.build function or State.build function. Therefore, it is often written that BuildContext is nothing more than a link to the location of the widget in the structure of all created widgets.

    It is worth adding that buildContext allows you to implement many functions (for example, showDialog, Theme.of, etc.) also continue the build chain, and their contexts will be different.

    I will add another hierarchy

    enter image description here

      You can look at BuildContext as a container object that stores the parent widget. This is the basis of what context is. The same context allows you to receive information about the branch of widgets on the branch of widgets, but this is already add. behavior.

      Example:

       return Scaffold( body: Container( child: Text("text"), ) ); 

      Take this simple markup. There are three widgets, the deepest is Text("text") . Text("text") has a build(BuildContext context) method, like all widgets that receive a BuildContext . In the case of the Text("text") method, the build(BuildContext context) will receive the context that the Container will store.