Passing around dependencies via InheritedWidget
The Flutter mechanism for passing around dependencies through the tree is called InheritedWidget
. You have certainly used it in your Flutter apps, even if you haven’t written one explicitly. Let’s take a look at what InheritedWidget
is and how it can help us on our state management journey.
What is InheritedWidget?
As you know, in Flutter, everything is a widget. So far, we have discussed various UI-related building widgets, such as Stateless
, Stateful
, and Render
, as well as their descendants. However, because these widgets are organized in a tree data structure, it is possible to perform various manipulations with it, such as a tree traversal. This capability is useful when we need to not only render static UI but also pass around shared data.
The Flutter framework includes a widget specifically for this purpose: InheritedWidget
. It is the last of the fundamental Flutter widgets. If we examine the framework.dart...