copyWith method

TextStyle copyWith ({bool inherit, Color color, Color backgroundColor, String fontFamily, List<String> fontFamilyFallback, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, Locale locale, Paint foreground, Paint background, List<Shadow> shadows, List<FontFeature> fontFeatures, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, double decorationThickness, String debugLabel })

Creates a copy of this text style but with the given fields replaced with the new values.

One of color or foreground must be null, and if this has foreground specified it will be given preference over any color parameter.

One of backgroundColor or background must be null, and if this has background specified it will be given preference over any backgroundColor parameter.

Implementation

TextStyle copyWith({
  bool inherit,
  Color color,
  Color backgroundColor,
  String fontFamily,
  List<String> fontFamilyFallback,
  double fontSize,
  FontWeight fontWeight,
  FontStyle fontStyle,
  double letterSpacing,
  double wordSpacing,
  TextBaseline textBaseline,
  double height,
  Locale locale,
  Paint foreground,
  Paint background,
  List<ui.Shadow> shadows,
  List<ui.FontFeature> fontFeatures,
  TextDecoration decoration,
  Color decorationColor,
  TextDecorationStyle decorationStyle,
  double decorationThickness,
  String debugLabel,
}) {
  assert(color == null || foreground == null, _kColorForegroundWarning);
  assert(backgroundColor == null || background == null, _kColorBackgroundWarning);
  String newDebugLabel;
  assert(() {
    if (this.debugLabel != null)
      newDebugLabel = debugLabel ?? '(${this.debugLabel}).copyWith';
    return true;
  }());
  return TextStyle(
    inherit: inherit ?? this.inherit,
    color: this.foreground == null && foreground == null ? color ?? this.color : null,
    backgroundColor: this.background == null && background == null ? backgroundColor ?? this.backgroundColor : null,
    fontFamily: fontFamily ?? this.fontFamily,
    fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
    fontSize: fontSize ?? this.fontSize,
    fontWeight: fontWeight ?? this.fontWeight,
    fontStyle: fontStyle ?? this.fontStyle,
    letterSpacing: letterSpacing ?? this.letterSpacing,
    wordSpacing: wordSpacing ?? this.wordSpacing,
    textBaseline: textBaseline ?? this.textBaseline,
    height: height ?? this.height,
    locale: locale ?? this.locale,
    foreground: foreground ?? this.foreground,
    background: background ?? this.background,
    shadows: shadows ?? this.shadows,
    fontFeatures: fontFeatures ?? this.fontFeatures,
    decoration: decoration ?? this.decoration,
    decorationColor: decorationColor ?? this.decorationColor,
    decorationStyle: decorationStyle ?? this.decorationStyle,
    decorationThickness: decorationThickness ?? this.decorationThickness,
    debugLabel: newDebugLabel,
  );
}