StrutStyle.fromTextStyle constructor
Builds a StrutStyle that contains values of the equivalent properties in
the provided textStyle
.
The named parameters override the textStyle
's argument's properties.
Since TextStyle does not contain leading or forceStrutHeight, these
values will take on default values (null and false) unless otherwise
specified.
If provided, fontSize must be positive and non-zero, leading must be zero or positive.
When textStyle
has a package and a new package
is also specified,
the entire font family fallback list should be redefined since the
textStyle
's package data is inherited by being prepended onto the
font family names. If fontFamilyFallback
is meant to be empty, pass
an empty list instead of null. This prevents the previous package name
from being prepended twice.
Implementation
StrutStyle.fromTextStyle(
TextStyle textStyle, {
String? fontFamily,
List<String>? fontFamilyFallback,
double? fontSize,
double? height,
TextLeadingDistribution? leadingDistribution,
this.leading, // TextStyle does not have an equivalent (yet).
FontWeight? fontWeight,
FontStyle? fontStyle,
this.forceStrutHeight,
String? debugLabel,
String? package,
}) : assert(fontSize == null || fontSize > 0),
assert(leading == null || leading >= 0),
assert(package == null || fontFamily != null || fontFamilyFallback != null),
fontFamily = fontFamily != null ? (package == null ? fontFamily : 'packages/$package/$fontFamily') : textStyle.fontFamily,
_fontFamilyFallback = fontFamilyFallback ?? textStyle.fontFamilyFallback,
height = height ?? textStyle.height,
leadingDistribution = leadingDistribution ?? textStyle.leadingDistribution,
fontSize = fontSize ?? textStyle.fontSize,
fontWeight = fontWeight ?? textStyle.fontWeight,
fontStyle = fontStyle ?? textStyle.fontStyle,
debugLabel = debugLabel ?? textStyle.debugLabel,
_package = package;