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.

link

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

Inheritance
Implementers

Constructors

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.
const

Properties

child Widget
The widget below this widget in the tree.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget 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.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited
updateShouldNotify(covariant InheritedWidget oldWidget) bool
Whether the framework should notify widgets that inherit from this widget.
inherited
wrap(BuildContext context, Widget child) Widget
Return a copy of this inherited theme with the specified child.

Operators

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

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.