copyWith method Null safety

TextStyle copyWith (
  1. {bool? inherit,
  2. Color? color,
  3. Color? backgroundColor,
  4. String? fontFamily,
  5. List<String>? fontFamilyFallback,
  6. double? fontSize,
  7. FontWeight? fontWeight,
  8. FontStyle? fontStyle,
  9. double? letterSpacing,
  10. double? wordSpacing,
  11. TextBaseline? textBaseline,
  12. double? height,
  13. Locale? locale,
  14. Paint? foreground,
  15. Paint? background,
  16. List<Shadow>? shadows,
  17. List<FontFeature>? fontFeatures,
  18. TextDecoration? decoration,
  19. Color? decorationColor,
  20. TextDecorationStyle? decorationStyle,
  21. double? decorationThickness,
  22. 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,
  );
}