InheritedTheme class abstract

An InheritedWidget that defines visual properties like colors and text styles, which the child's subtree depends on.

The wrap method is used by captureAll and CapturedThemes.wrap to construct a widget that will wrap a child in all of the inherited themes which are present in a specified part of the widget tree.

A widget that's shown in a different context from the one it's built in, like the contents of a new route or an overlay, will be able to see the ancestor inherited themes of the context it was built in.

This example demonstrates how InheritedTheme.capture() can be used to wrap the contents of a new route with the inherited themes that are present when the route was built - but are not present when route is actually shown.

If the same code is run without `InheritedTheme.capture(), the new route's Text widget will inherit the "something must be wrong" fallback text style, rather than the default text style defined in MyApp.


To create a local project with this code sample, run:
flutter create --sample=widgets.InheritedTheme.1 mysample



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


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


createElement() InheritedElement
Inflates this configuration to a concrete instance.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.
updateShouldNotify(covariant InheritedWidget oldWidget) bool
Whether the framework should notify widgets that inherit from this widget.
wrap(BuildContext context, Widget child) Widget
Return a copy of this inherited theme with the specified child.


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

Static Methods

capture({required BuildContext from, required BuildContext? to}) CapturedThemes
Returns a CapturedThemes object that includes all the InheritedThemes between the given from and to BuildContexts.
captureAll(BuildContext context, Widget child, {BuildContext? to}) Widget
Returns a widget that will wrap child in all of the inherited themes which are present between context and the specified to BuildContext.