YaruTheme class
Applies Yaru theme to descendant widgets.
Descendant widgets obtain the current theme's YaruThemeData object using YaruTheme.of. When a widget uses YaruTheme.of, it is automatically rebuilt if the theme later changes, so that the changes can be applied.
There are two ways to use YaruTheme - with a child widget or as a builder.
Child widget
The simplest way to use YaruTheme is to wrap a child widget in it.
MaterialApp(
home: YaruTheme(
child: ...
),
)
Note: YaruTheme must be a descendant of MaterialApp to avoid that MaterialApp overrides YaruTheme.
When used like this, YaruTheme internally creates an AnimatedTheme widget populated with the appropriate Yaru theme data. Moreover, The child widget gets automatically rebuilt whenever the system theme changes.
Builder
An alternative way to use YaruTheme is to use it as a builder.
YaruTheme(
builder: (context, yaru, child) {
return MaterialApp(
theme: yaru.theme,
darkTheme: yaru.darkTheme,
home: ...
);
},
)
When used like this, YaruTheme does not create an AnimatedTheme widget. Instead, it passes a YaruThemeData object to the builder function to allow passing the desired values to MaterialApp. This has the advantage that any widget created by MaterialApp, such as the built-in Navigator, gains Yaru-theme as well.
Theme data overrides
The data property can be used to override parts of the default theme data. For example, the following code overrides the default page transitions and visual density:
YaruTheme(
data: YaruThemeData(
pageTransitionsTheme: PageTransitionsTheme(/*...*/),
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
),
builder: (context, yaru, child) {
return MaterialApp(
theme: yaru.theme,
darkTheme: yaru.darkTheme,
home: ...
);
},
)
See also:
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- YaruTheme
Constructors
-
YaruTheme({Key? key, ValueWidgetBuilder<
YaruThemeData> ? builder, Widget? child, YaruThemeData data = const YaruThemeData(), @visibleForTesting Platform? platform, @visibleForTesting YaruSettings? settings}) -
Applies the given theme data to child.
const
Properties
-
builder
→ ValueWidgetBuilder<
YaruThemeData> ? -
Builds the widget below this widget in the tree.
final
- child → Widget?
-
The widget below this widget in the tree.
final
- data → YaruThemeData
-
Specifies the theme for descendant widgets.
final
- 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(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< YaruTheme> -
Creates the mutable state for this widget at a given location in the tree.
override
-
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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
maybeOf(
BuildContext context) → YaruThemeData? -
An optional data from the closest YaruTheme instance that encloses the
given context or
null
if there is no such ancestor. -
of(
BuildContext context) → YaruThemeData - The data from the closest YaruTheme instance that encloses the given context.