copyWith method

TextStyle copyWith(
  1. {bool? inherit,
  2. Color? color,
  3. Color? backgroundColor,
  4. double? fontSize,
  5. FontWeight? fontWeight,
  6. FontStyle? fontStyle,
  7. double? letterSpacing,
  8. double? wordSpacing,
  9. TextBaseline? textBaseline,
  10. double? height,
  11. TextLeadingDistribution? leadingDistribution,
  12. Locale? locale,
  13. Paint? foreground,
  14. Paint? background,
  15. List<Shadow>? shadows,
  16. List<FontFeature>? fontFeatures,
  17. List<FontVariation>? fontVariations,
  18. TextDecoration? decoration,
  19. Color? decorationColor,
  20. TextDecorationStyle? decorationStyle,
  21. double? decorationThickness,
  22. String? debugLabel,
  23. String? fontFamily,
  24. List<String>? fontFamilyFallback,
  25. String? package,
  26. TextOverflow? overflow}
)

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,
  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,
}) {
  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,
    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,
    leadingDistribution: leadingDistribution ?? this.leadingDistribution,
    locale: locale ?? this.locale,
    foreground: foreground ?? this.foreground,
    background: background ?? this.background,
    shadows: shadows ?? this.shadows,
    fontFeatures: fontFeatures ?? this.fontFeatures,
    fontVariations: fontVariations ?? this.fontVariations,
    decoration: decoration ?? this.decoration,
    decorationColor: decorationColor ?? this.decorationColor,
    decorationStyle: decorationStyle ?? this.decorationStyle,
    decorationThickness: decorationThickness ?? this.decorationThickness,
    debugLabel: newDebugLabel,
    fontFamily: fontFamily ?? _fontFamily,
    fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback,
    package: package ?? _package,
    overflow: overflow ?? this.overflow,
  );
}