midFlutter
What are InheritedWidgets and how do they work?
Updated Apr 28, 2026
Short answer
InheritedWidgets provide a mechanism to efficiently pass data down the widget tree without explicitly passing it through constructors.
Deep explanation
When an InheritedWidget updates, it tells the framework to rebuild only the specific descendant widgets that depend on it. It sits near the top of the tree, and descendants use context.dependOnInheritedWidgetOfExactType() to access its data and register for rebuilds.
Real-world example
Flutter's core Theme.of(context) and MediaQuery.of(context) are both built using InheritedWidgets.
Common mistakes
- Creating deep class hierarchies just to pass simple data instead of using an InheritedWidget or Provider.
Follow-up questions
- What is the updateShouldNotify method?
- Why is Provider preferred over raw InheritedWidget?