apply method

TextStyle apply ({Color color, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String fontFamily, double fontSizeFactor: 1.0, double fontSizeDelta: 0.0, int fontWeightDelta: 0, double letterSpacingFactor: 1.0, double letterSpacingDelta: 0.0, double wordSpacingFactor: 1.0, double wordSpacingDelta: 0.0, double heightFactor: 1.0, double heightDelta: 0.0 })

Creates a copy of this text style replacing or altering the specified properties.

The non-numeric properties color, fontFamily, decoration, decorationColor and decorationStyle are replaced with the new values.

foreground will be given preference over color if it is not null.

The numeric properties are multiplied by the given factors and then incremented by the given deltas.

For example, style.apply(fontSizeFactor: 2.0, fontSizeDelta: 1.0) would return a TextStyle whose fontSize is style.fontSize * 2.0 + 1.0.

For the fontWeight, the delta is applied to the FontWeight enum index values, so that for instance style.apply(fontWeightDelta: -2) when applied to a style whose fontWeight is FontWeight.w500 will return a TextStyle with a FontWeight.w300.

The numeric arguments must not be null.

If the underlying values are null, then the corresponding factors and/or deltas must not be specified.

If foreground is specified on this object, then applying color here will have no effect.

Implementation

TextStyle apply({
  Color color,
  TextDecoration decoration,
  Color decorationColor,
  TextDecorationStyle decorationStyle,
  String fontFamily,
  double fontSizeFactor = 1.0,
  double fontSizeDelta = 0.0,
  int fontWeightDelta = 0,
  double letterSpacingFactor = 1.0,
  double letterSpacingDelta = 0.0,
  double wordSpacingFactor = 1.0,
  double wordSpacingDelta = 0.0,
  double heightFactor = 1.0,
  double heightDelta = 0.0,
}) {
  assert(fontSizeFactor != null);
  assert(fontSizeDelta != null);
  assert(fontSize != null || (fontSizeFactor == 1.0 && fontSizeDelta == 0.0));
  assert(fontWeightDelta != null);
  assert(fontWeight != null || fontWeightDelta == 0.0);
  assert(letterSpacingFactor != null);
  assert(letterSpacingDelta != null);
  assert(letterSpacing != null || (letterSpacingFactor == 1.0 && letterSpacingDelta == 0.0));
  assert(wordSpacingFactor != null);
  assert(wordSpacingDelta != null);
  assert(wordSpacing != null || (wordSpacingFactor == 1.0 && wordSpacingDelta == 0.0));
  assert(heightFactor != null);
  assert(heightDelta != null);
  assert(heightFactor != null || (heightFactor == 1.0 && heightDelta == 0.0));

  String modifiedDebugLabel;
  assert(() {
    if (debugLabel != null)
      modifiedDebugLabel = '($debugLabel).apply';
    return true;
  }());

  return TextStyle(
    inherit: inherit,
    color: foreground == null ? color ?? this.color : null,
    fontFamily: fontFamily ?? this.fontFamily,
    fontSize: fontSize == null ? null : fontSize * fontSizeFactor + fontSizeDelta,
    fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1)],
    fontStyle: fontStyle,
    letterSpacing: letterSpacing == null ? null : letterSpacing * letterSpacingFactor + letterSpacingDelta,
    wordSpacing: wordSpacing == null ? null : wordSpacing * wordSpacingFactor + wordSpacingDelta,
    textBaseline: textBaseline,
    height: height == null ? null : height * heightFactor + heightDelta,
    locale: locale,
    foreground: foreground != null ? foreground : null,
    background: background,
    shadows: shadows,
    decoration: decoration ?? this.decoration,
    decorationColor: decorationColor ?? this.decorationColor,
    decorationStyle: decorationStyle ?? this.decorationStyle,
    debugLabel: modifiedDebugLabel,
  );
}