copyWith method

Text copyWith({
  1. Key? textKey,
  2. StrutStyle? textStrutStyle,
  3. TextAlign? textAlign,
  4. TextDirection? textDirection,
  5. Locale? textLocale,
  6. bool? textSoftWrap,
  7. TextOverflow? textOverflow,
  8. double? textScaleFactor,
  9. int? textMaxLines,
  10. String? textSemanticsLabel,
  11. TextWidthBasis? textWidthBasis,
  12. TextHeightBehavior? textHeightBehavior,
  13. bool? styleInherit,
  14. Color? styleColor,
  15. Color? styleBackgroundColor,
  16. double? styleFontSize,
  17. FontWeight? styleFontWeight,
  18. FontStyle? styleFontStyle,
  19. double? styleLetterSpacing,
  20. double? styleWordSpacing,
  21. TextBaseline? styleTextBaseline,
  22. double? styleHeight,
  23. TextLeadingDistribution? styleLeadingDistribution,
  24. Locale? styleLocale,
  25. Paint? styleForeground,
  26. Paint? styleBackground,
  27. List<Shadow>? styleShadows,
  28. List<FontFeature>? styleFontFeatures,
  29. TextDecoration? styleDecoration,
  30. Color? styleDecorationColor,
  31. TextDecorationStyle? styleDecorationStyle,
  32. double? styleDecorationThickness,
  33. String? styleDebugLabel,
  34. String? styleFontFamily,
  35. List<String>? styleFontFamilyFallback,
  36. String? stylePackage,
  37. TextOverflow? styleOverflow,
})

Copy your Text while adding more style like if you use toH1Text Extension then while using copyWith you can also customize it like change color with styleColor In all member of copyWith prefix are indicate where it use for example text represent they are use for Text widget and style are represent they are in TextStyle.

Implementation

Text copyWith({
  Key? textKey,
  StrutStyle? textStrutStyle,
  TextAlign? textAlign,
  TextDirection? textDirection,
  Locale? textLocale,
  bool? textSoftWrap,
  TextOverflow? textOverflow,
  double? textScaleFactor,
  int? textMaxLines,
  String? textSemanticsLabel,
  TextWidthBasis? textWidthBasis,
  TextHeightBehavior? textHeightBehavior,

  /// for style
  bool? styleInherit,
  Color? styleColor,
  Color? styleBackgroundColor,
  double? styleFontSize,
  FontWeight? styleFontWeight,
  FontStyle? styleFontStyle,
  double? styleLetterSpacing,
  double? styleWordSpacing,
  TextBaseline? styleTextBaseline,
  double? styleHeight,
  TextLeadingDistribution? styleLeadingDistribution,
  Locale? styleLocale,
  Paint? styleForeground,
  Paint? styleBackground,
  List<Shadow>? styleShadows,
  List<FontFeature>? styleFontFeatures,
  TextDecoration? styleDecoration,
  Color? styleDecorationColor,
  TextDecorationStyle? styleDecorationStyle,
  double? styleDecorationThickness,
  String? styleDebugLabel,
  String? styleFontFamily,
  List<String>? styleFontFamilyFallback,
  String? stylePackage,
  TextOverflow? styleOverflow,
}) {
  String _text = data ?? "";
  Key? _key = textKey ?? key;
  TextStyle _style = style ?? TextStyle();
  StrutStyle? _strutStyle = textStrutStyle ?? strutStyle;
  TextAlign? _textAlign = textAlign ?? this.textAlign;
  TextDirection? _textDirection = textDirection ?? this.textDirection;
  Locale? _locale = textLocale ?? locale;
  bool? _softWrap = textSoftWrap ?? softWrap;
  TextOverflow? _overflow = textOverflow ?? overflow;
  double? _textScaleFactor = textScaleFactor ?? this.textScaleFactor;
  int? _maxLines = textMaxLines ?? maxLines;
  String? _semanticsLabel = textSemanticsLabel ?? semanticsLabel;
  TextWidthBasis? _textWidthBasis = textWidthBasis ?? this.textWidthBasis;
  TextHeightBehavior? _textHeightBehavior =
      textHeightBehavior ?? this.textHeightBehavior;

  return Text(
    _text,
    key: _key,
    style: _style.copyWith(
      inherit: styleInherit,
      color: styleColor,
      backgroundColor: styleBackgroundColor,
      fontSize: styleFontSize,
      fontWeight: styleFontWeight,
      fontStyle: styleFontStyle,
      letterSpacing: styleLetterSpacing,
      wordSpacing: styleWordSpacing,
      textBaseline: styleTextBaseline,
      height: styleHeight,
      leadingDistribution: styleLeadingDistribution,
      locale: styleLocale,
      foreground: styleForeground,
      background: styleBackground,
      shadows: styleShadows,
      fontFeatures: styleFontFeatures,
      decoration: styleDecoration,
      decorationColor: styleDecorationColor,
      decorationStyle: styleDecorationStyle,
      decorationThickness: styleDecorationThickness,
      debugLabel: styleDebugLabel,
      fontFamily: styleFontFamily,
      fontFamilyFallback: styleFontFamilyFallback,
      overflow: styleOverflow,
      package: stylePackage,
    ),
    strutStyle: _strutStyle,
    textAlign: _textAlign,
    textDirection: _textDirection,
    locale: _locale,
    softWrap: _softWrap,
    overflow: _overflow,
    textScaleFactor: _textScaleFactor,
    maxLines: _maxLines,
    semanticsLabel: _semanticsLabel,
    textWidthBasis: _textWidthBasis,
    textHeightBehavior: _textHeightBehavior,
  );
}