MaterialStateTextStyle class Null safety

Defines a TextStyle that is also a MaterialStateProperty.

This class exists to enable widgets with TextStyle valued properties to also accept MaterialStateProperty<TextStyle> values. A material state text style property represents a text style which depends on a widget's "interactive state". This state is represented as a Set of MaterialStates, like MaterialState.pressed, MaterialState.focused and MaterialState.hovered.

MaterialStateTextStyle should only be used with widgets that document their support, like InputDecoration.labelStyle.

To use a MaterialStateTextStyle, you can either:

  1. Create a subclass of MaterialStateTextStyle and implement the abstract resolve method.
  2. Use MaterialStateTextStyle.resolveWith and pass in a callback that will be used to resolve the color in the given states.

If a MaterialStateTextStyle is used for a property or a parameter that doesn't support resolving MaterialStateProperty<TextStyle>s, then its default color value will be used for all states.

To define a const MaterialStateTextStyle, you'll need to extend MaterialStateTextStyle and override its resolve method. You'll also need to provide a defaultValue to the super constructor, so that we can know at compile-time what its default color is.

Inheritance
Implemented types

Constructors

MaterialStateTextStyle()
Abstract const constructor. This constructor enables subclasses to provide const constructors so that they can be used in const expressions.
const

Properties

background Paint?
The paint drawn as a background for the text.
finalinherited
backgroundColor Color?
The color to use as the background for the text.
finalinherited
color Color?
The color to use when painting the text.
finalinherited
debugLabel String?
A human-readable description of this text style.
finalinherited
decoration TextDecoration?
The decorations to paint near the text (e.g., an underline).
finalinherited
decorationColor Color?
The color in which to paint the text decorations.
finalinherited
decorationStyle TextDecorationStyle?
The style in which to paint the text decorations (e.g., dashed).
finalinherited
decorationThickness double?
The thickness of the decoration stroke as a multiplier of the thickness defined by the font.
finalinherited
fontFamily String?
The name of the font to use when painting the text (e.g., Roboto).
finalinherited
fontFamilyFallback List<String>?
The ordered list of font families to fall back on when a glyph cannot be found in a higher priority font family.
read-onlyinherited
fontFeatures List<FontFeature>?
A list of FontFeatures that affect how the font selects glyphs.
finalinherited
fontSize double?
The size of glyphs (in logical pixels) to use when painting the text.
finalinherited
fontStyle FontStyle?
The typeface variant to use when drawing the letters (e.g., italics).
finalinherited
fontVariations List<FontVariation>?
A list of FontVariations that affect how a variable font is rendered.
finalinherited
fontWeight FontWeight?
The typeface thickness to use when painting the text (e.g., bold).
finalinherited
foreground Paint?
The paint drawn as a foreground for the text.
finalinherited
hashCode int
The hash code for this object.
read-onlyinherited
height double?
The height of this text span, as a multiple of the font size.
finalinherited
inherit bool
Whether null values are replaced with their value in an ancestor text style (e.g., in a TextSpan tree).
finalinherited
leadingDistribution TextLeadingDistribution?
How the vertical space added by the height multiplier should be distributed over and under the text.
finalinherited
letterSpacing double?
The amount of space (in logical pixels) to add between each letter. A negative value can be used to bring the letters closer.
finalinherited
locale Locale?
The locale used to select region-specific glyphs.
finalinherited
overflow TextOverflow?
How visual text overflow should be handled.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
shadows List<Shadow>?
A list of Shadows that will be painted underneath the text.
finalinherited
textBaseline TextBaseline?
The common baseline that should be aligned between this text span and its parent text span, or, for the root text spans, with the line box.
finalinherited
wordSpacing double?
The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between each word). A negative value can be used to bring the words closer.
finalinherited

Methods

apply({Color? color, Color? backgroundColor, TextDecoration? decoration, Color? decorationColor, TextDecorationStyle? decorationStyle, double decorationThicknessFactor = 1.0, double decorationThicknessDelta = 0.0, String? fontFamily, List<String>? fontFamilyFallback, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, FontStyle? fontStyle, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0, TextBaseline? textBaseline, TextLeadingDistribution? leadingDistribution, Locale? locale, List<Shadow>? shadows, List<FontFeature>? fontFeatures, List<FontVariation>? fontVariations, String? package, TextOverflow? overflow}) TextStyle
Creates a copy of this text style replacing or altering the specified properties.
inherited
compareTo(TextStyle other) RenderComparison
Describe the difference between this style and another, in terms of how much damage it will make to the rendering.
inherited
copyWith({bool? inherit, Color? color, Color? backgroundColor, double? fontSize, FontWeight? fontWeight, FontStyle? fontStyle, double? letterSpacing, double? wordSpacing, TextBaseline? textBaseline, double? height, TextLeadingDistribution? leadingDistribution, Locale? locale, Paint? foreground, Paint? background, List<Shadow>? shadows, List<FontFeature>? fontFeatures, List<FontVariation>? fontVariations, TextDecoration? decoration, Color? decorationColor, TextDecorationStyle? decorationStyle, double? decorationThickness, String? debugLabel, String? fontFamily, List<String>? fontFamilyFallback, String? package, TextOverflow? overflow}) TextStyle
Creates a copy of this text style but with the given fields replaced with the new values.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties, {String prefix = ''}) → void
Adds all properties prefixing property names with the optional prefix.
inherited
getParagraphStyle({TextAlign? textAlign, TextDirection? textDirection, double textScaleFactor = 1.0, String? ellipsis, int? maxLines, TextHeightBehavior? textHeightBehavior, Locale? locale, String? fontFamily, double? fontSize, FontWeight? fontWeight, FontStyle? fontStyle, double? height, StrutStyle? strutStyle}) ParagraphStyle
The style information for paragraphs, encoded for use by dart:ui.
inherited
getTextStyle({double textScaleFactor = 1.0}) TextStyle
The style information for text runs, encoded for use by dart:ui.
inherited
merge(TextStyle? other) TextStyle
Returns a new text style that is a combination of this style and the given other style.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
resolve(Set<MaterialState> states) TextStyle
Returns a TextStyle that's to be used when a Material component is in the specified state.
override
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.
inherited

Static Methods

resolveWith(MaterialPropertyResolver<TextStyle> callback) MaterialStateTextStyle
Creates a MaterialStateTextStyle from a MaterialPropertyResolver<TextStyle> callback function.
override