adjust method

TextStyle adjust({
  1. double? sizeMultiplier,
  2. int? weightStep,
  3. double? fontSize,
  4. FontWeight? fontWeight,
  5. Color? color,
  6. bool clearColor = false,
  7. Color? backgroundColor,
  8. double? letterSpacing,
  9. double? wordSpacing,
  10. double? height,
  11. Paint? foreground,
  12. Paint? background,
  13. TextDecoration? decoration,
  14. Color? decorationColor,
  15. TextDecorationStyle? decorationStyle,
  16. double? decorationThickness,
  17. String? fontFamily,
  18. List<String>? fontFamilyFallback,
  19. List<Shadow>? shadows,
  20. FontStyle? fontStyle,
})

Returns a new TextStyle with adjusted properties such as sizeMultiplier and weightStep.

  • sizeMultiplier: Multiplies fontSize by this factor (if fontSize is not null).
  • weightStep: Steps the fontWeight by an offset (e.g. +1 changes w100 to w200, w300 to w400; -1 makes it lighter). If fontWeight is currently null, defaults to FontWeight.normal before stepping.
  • All other parameters standardly override properties via copyWith.

Implementation

TextStyle adjust({
  double? sizeMultiplier,
  int? weightStep,
  double? fontSize,
  FontWeight? fontWeight,
  Color? color,
  bool clearColor = false,
  Color? backgroundColor,
  double? letterSpacing,
  double? wordSpacing,
  double? height,
  Paint? foreground,
  Paint? background,
  TextDecoration? decoration,
  Color? decorationColor,
  TextDecorationStyle? decorationStyle,
  double? decorationThickness,
  String? fontFamily,
  List<String>? fontFamilyFallback,
  List<Shadow>? shadows,
  FontStyle? fontStyle,
}) {
  final effectiveFontSize =
      fontSize ?? (sizeMultiplier != null && this.fontSize != null ? this.fontSize! * sizeMultiplier : this.fontSize);

  final effectiveFontWeight =
      fontWeight ?? (weightStep != null ? (this.fontWeight ?? FontWeight.normal).step(weightStep) : this.fontWeight);

  if (clearColor) {
    return TextStyle(
      inherit: inherit,
      color: null,
      backgroundColor: backgroundColor ?? this.backgroundColor,
      fontSize: effectiveFontSize,
      fontWeight: effectiveFontWeight,
      fontStyle: fontStyle ?? this.fontStyle,
      letterSpacing: letterSpacing ?? this.letterSpacing,
      wordSpacing: wordSpacing ?? this.wordSpacing,
      textBaseline: textBaseline,
      height: height ?? this.height,
      leadingDistribution: leadingDistribution,
      locale: locale,
      foreground: foreground ?? this.foreground,
      background: background ?? this.background,
      shadows: shadows ?? this.shadows,
      fontFeatures: fontFeatures,
      fontVariations: fontVariations,
      decoration: decoration ?? this.decoration,
      decorationColor: decorationColor ?? this.decorationColor,
      decorationStyle: decorationStyle ?? this.decorationStyle,
      decorationThickness: decorationThickness ?? this.decorationThickness,
      debugLabel: debugLabel,
      fontFamily: fontFamily ?? this.fontFamily,
      fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
      overflow: overflow,
    );
  }

  return copyWith(
    fontSize: effectiveFontSize,
    fontWeight: effectiveFontWeight,
    color: color,
    backgroundColor: backgroundColor,
    letterSpacing: letterSpacing,
    wordSpacing: wordSpacing,
    height: height,
    foreground: foreground,
    background: background,
    decoration: decoration,
    decorationColor: decorationColor,
    decorationStyle: decorationStyle,
    decorationThickness: decorationThickness,
    fontFamily: fontFamily,
    fontFamilyFallback: fontFamilyFallback,
    shadows: shadows,
    fontStyle: fontStyle,
  );
}