Flutter & Dart (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is `InheritedWidget` and how does `of(context)` work under the hood?
senior LevelSystem Design
In Simple Words:
InheritedWidget is the base class for widgets that efficiently propagate data down the widget tree:
- When a descendant widget calls
MyInherited.of(context), Flutter registers the descendant'sElementas a dependent. - When the
InheritedWidgetrebuilds with new data (updateShouldNotify() == true), Flutter automatically rebuilds only the registered dependent descendant widgets, skipping non-dependent siblings!