Blog

BuildContext

Published 1 min read

BuildContext

Each widget doesn't exist on its own; it exists together with other widgets.
But a widget by itself has no way of knowing where it exists.
That means the widget has no location information about where it sits within the widget tree.

abstract class Widget extends DiagnosticableTree { Element createElement(); // abstract method }
abstract class Element extends DiagnosticableTree implements BuildContext {

So a widget creates an Element through the createElement() function.
The Element class implements BuildContext.
An Element holds information like the Widget, parent, childrent, size, Render Object, and so on.

In conclusion, BuildContext is
A handle to the location of a widget in the widget tree.
a class that holds a widget's location information.

Comments

Leaving a comment stores your nickname (or GitHub profile info). Privacy policy

GitHub