InheritedComponent class abstract

Base class for components that efficiently propagate information down the tree.

To obtain the nearest instance of a particular type of inherited component from a build context, use BuildContext.dependOnInheritedComponentOfExactType.

Inherited components, when referenced in this way, will cause the consumer to rebuild when the inherited component itself changes state.

Implementing the of method

The convention is to provide a static method of on the InheritedComponent which does the call to BuildContext.dependOnInheritedComponentOfExactType. This allows the class to define its own fallback logic in case there isn't a component in scope. In the example above, the value returned will be null in that case, but it could also have defaulted to a value.

Occasionally, the inherited component is an implementation detail of another class, and is therefore private. The of method in that case is typically put on the public class instead.

Calling the of method

When using the of method, the context must be a descendant of the InheritedComponent, meaning it must be "below" the InheritedComponent in the tree.

See also:

  • StatefulComponent and State, for components that can build differently several times over their lifetime.
  • StatelessComponent, for components that always build the same way given a particular configuration and ambient state.
  • Component, for an overview of components in general.
Inheritance

Constructors

InheritedComponent({required Component child, Key? key})
Abstract const constructor. This constructor enables subclasses to provide const constructors so that they can be used in const expressions.
const

Properties

child Component
The component below this component in the tree.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one component replaces another component in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() InheritedElement
Inflates this configuration to a concrete instance.
override
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 InheritedComponent oldComponent) bool
Whether the framework should notify components that inherit from this component.

Operators

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