InheritedWidget class abstract

A widget that the elements below it find by its type in constant time (BuildContext.dependOnInheritedWidgetOfExactType), the nearest one of a type hiding those above it. Those that depend on it are rebuilt when it is replaced by one that updateShouldNotifys; the others are not.

A value for a subtree, read with a static of as the framework's own inherited widgets (Theme, DefaultTextStyle) are:

final class Account extends InheritedWidget {
  const Account({required this.user, required super.child, super.key});

  final String user;

  static String of(BuildContext context) =>
      context.dependOnInheritedWidgetOfExactType<Account>()!.user;

  @override
  bool updateShouldNotify(Account oldWidget) => user != oldWidget.user;
}

See also:

  • ListenableBuilder, for a value that changes without its parent rebuilding.
Inheritance
Implementers

Constructors

InheritedWidget({required Widget child, Key? key})
For subclasses: shows child, whose subtree finds this widget.
const

Properties

child → Widget
The widget below this one, which it shows as it is.
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Tells this widget apart from its siblings; see Key.
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → InheritedElement
Inflates this widget into a new element for the tree.
override
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Adds what describes this widget in its element's description (Element.describe) to properties, those not worth showing (a default) left out; an override calls this first. A render object widget adds only what its render object does not show. Only Element.describe calls it: a frame never does.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
updateShouldNotify(covariant InheritedWidget oldWidget) → bool
Whether the elements that depend on this widget are to be rebuilt now that it replaced oldWidget.

Operators

operator ==(Object other) → bool
The equality operator.
inherited