What is InheritedModel and how does it differ from InheritedWidget?
TL;DR: InheritedModel extends InheritedWidget with aspect-based selective rebuilds. Widgets declare which aspect they depend on, and only rebuild when that specific aspect changes — finer control than InheritedWidget.
Full Answer
With plain InheritedWidget, any change triggers a rebuild of all dependents. InheritedModel introduces 'aspects' — named slices of the model. Widgets specify which aspect they depend on and only rebuild for that aspect.
This is the mechanism behind Flutter's own MediaQuery — MediaQuery.sizeOf(context) only depends on the size aspect, not the full MediaQuery data.
InheritedModel is lower-level. In practice, context.select() in Provider achieves similar selective rebuild behavior with less boilerplate.
Code Examples
Widget depending on 'color' rebuilds only when primaryColor changes, not when fontSize changes
Common Mistakes
- ✗Using InheritedModel when InheritedWidget + multiple consumers is simpler
- ✗Typo in aspect string — silent failure; widget depends on wrong or no aspect
Interview Tip
Mentioning that MediaQuery.sizeOf() uses InheritedModel-style aspects shows you've studied Flutter's own source code.