DesignStyle class
How one part of a look looks, as Material's ButtonStyle is: every slot
resolves for the part's states (WidgetState.disabled,
WidgetState.hovered, WidgetState.focused, WidgetState.pressed,
WidgetState.selected, WidgetState.error).
A part reads each slot from its own style: first, then from its
component theme, then from the theme-wide knobs (shapes, strokes,
density, typeface), then from the look's own default. A slot that is
null, or resolves to null for the states at hand, falls through to the
next. DesignStyleOf reads the first two layers for a part.
| slot | what it sets |
|---|---|
| fill | the face or plate |
| foreground | the words and icons on it |
| edge | the rim's colour, at the look's width |
| overlay | the wash over the face in the states it names |
| side | the whole rim, colour and width; it wins over edge |
| shape | the outline: the look's own borders, or any OutlinedBorder |
| padding | the room between the rim and what stands inside |
| minimumSize | the least the face stands; the tap target is the look's floor |
| textStyle | the words' style, merged over the look's (its colour comes from foreground) |
| iconSize | an icon's size |
Each part's doc says which slots it reads. A look names this class as its
own (typedef ComicStyle = DesignStyle;), so every look's parts take the
same style, read the same way.
final style = DesignStyle(
fill: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.pressed)
? const Color(0xFF1D4ED8)
: const Color(0xFF2563EB),
),
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 20)),
);
A look that needs a slot of its own (a groove's depth, a glow) leaves the alias for a subclass under the same name, which keeps every call that builds one compiling and passes where a DesignStyle is read:
class NeumorphicStyle extends DesignStyle { const NeumorphicStyle({super.fill, …, this.depth}); final WidgetStateProperty<double?>? depth; }
It then overrides copyWith, merge, lerp (as a static of its own),
==, hashCode and debugFillProperties for the new slot, and reads it
with first.
See also:
- DesignStyleOf, a part's layers read at its states.
ButtonStyle, Material's counterpart, which this follows.
- Mixed-in types
- Annotations
Constructors
-
DesignStyle({WidgetStateProperty<
Color?> ? fill, WidgetStateProperty<Color?> ? foreground, WidgetStateProperty<Color?> ? edge, WidgetStateProperty<Color?> ? overlay, WidgetStateProperty<BorderSide?> ? side, WidgetStateProperty<OutlinedBorder?> ? shape, WidgetStateProperty<EdgeInsetsGeometry?> ? padding, WidgetStateProperty<Size?> ? minimumSize, WidgetStateProperty<TextStyle?> ? textStyle, WidgetStateProperty<double?> ? iconSize}) -
Every slot null: the next layer's, down to the look's own.
const
-
DesignStyle.layered(List<
DesignStyle?> layers) -
layersin priority order, as one style: each slot is the first layer's that resolves to a value for the states at hand. How a composite part forwards its own style and its component theme to a part inside it. Unlike merge, which keeps a whole slot, this falls through inside a slot, state by state.factory
Properties
-
edge
→ WidgetStateProperty<
Color?> ? -
The rim's colour, drawn at the look's width.
final
-
fill
→ WidgetStateProperty<
Color?> ? -
The face or plate.
final
-
foreground
→ WidgetStateProperty<
Color?> ? -
What stands on the face: the words and icons, a tick, a lever.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
-
iconSize
→ WidgetStateProperty<
double?> ? -
An icon's size.
final
- isEmpty → bool
-
Whether every slot is null.
no setter
-
minimumSize
→ WidgetStateProperty<
Size?> ? -
The least size of the face.
final
-
overlay
→ WidgetStateProperty<
Color?> ? -
The wash over the face in the states it names, drawn in the part's
outline. Each look says which states its own wash covers.
final
-
padding
→ WidgetStateProperty<
EdgeInsetsGeometry?> ? -
The room between the rim and what stands inside.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shape
→ WidgetStateProperty<
OutlinedBorder?> ? -
The outline.
final
-
side
→ WidgetStateProperty<
BorderSide?> ? -
The whole rim, colour and width. Wins over edge.
final
-
textStyle
→ WidgetStateProperty<
TextStyle?> ? -
The words' style, merged over the look's.
final
Methods
-
copyWith(
{WidgetStateProperty< Color?> ? fill, WidgetStateProperty<Color?> ? foreground, WidgetStateProperty<Color?> ? edge, WidgetStateProperty<Color?> ? overlay, WidgetStateProperty<BorderSide?> ? side, WidgetStateProperty<OutlinedBorder?> ? shape, WidgetStateProperty<EdgeInsetsGeometry?> ? padding, WidgetStateProperty<Size?> ? minimumSize, WidgetStateProperty<TextStyle?> ? textStyle, WidgetStateProperty<double?> ? iconSize}) → DesignStyle - This with the named slots changed.
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
merge(
DesignStyle? other) → DesignStyle -
This, with
other's slots where this has none, asButtonStyle.merge: a slot is kept whole. DesignStyle.layered falls through within one. -
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
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
first<
T> (Iterable< DesignStyle?> layers, WidgetStateProperty<T?> ? slot(DesignStyle style), Set<WidgetState> states) → T? -
The first of
layerswhoseslotgives a value forstates: how a part reads itsstyle:, then its component theme. Null when none does, so the part goes on to the theme-wide knobs and its own default. -
lerp(
DesignStyle? a, DesignStyle? b, double t) → DesignStyle? -
Between
aandb, slot by slot, asButtonStyle.lerp: colours, sides, insets, sizes and type blend; shapes morph where their borders can (OutlinedBorder.lerp) and snap at the middle where they cannot; a value on one side only snaps at the middle. -
resolve(
WidgetStateProperty< Color?> ? slot, Set<WidgetState> states, Color fallback) → Color -
slotforstates, orfallback.