fallback method

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

Returns a new TextStyle with null properties replaced by fallback values.

For each nullable property, if the current value is null and a fallback value is provided, the fallback value is used. Otherwise, the current value (whether null or not) is retained.

Implementation

TextStyle fallback({
  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,
  TextOverflow? overflow,
}) {
  /// Helper function to apply fallback logic for nullable properties.
  T? fallback<T>(T? currentValue, T? newValue) {
    return currentValue == null && newValue != null ? newValue : currentValue;
  }

  return TextStyle(
    color: fallback(this.color, color),
    backgroundColor: fallback(this.backgroundColor, backgroundColor),
    fontSize: fallback(this.fontSize, fontSize),
    fontWeight: fallback(this.fontWeight, fontWeight),
    fontStyle: fallback(this.fontStyle, fontStyle),
    letterSpacing: fallback(this.letterSpacing, letterSpacing),
    wordSpacing: fallback(this.wordSpacing, wordSpacing),
    textBaseline: fallback(this.textBaseline, textBaseline),
    height: fallback(this.height, height),
    leadingDistribution: fallback(
      this.leadingDistribution,
      leadingDistribution,
    ),
    locale: fallback(this.locale, locale),
    foreground: fallback(this.foreground, foreground),
    background: fallback(this.background, background),
    shadows: fallback(this.shadows, shadows),
    fontFeatures: fallback(this.fontFeatures, fontFeatures),
    fontVariations: fallback(this.fontVariations, fontVariations),
    decoration: fallback(this.decoration, decoration),
    decorationColor: fallback(this.decorationColor, decorationColor),
    decorationStyle: fallback(this.decorationStyle, decorationStyle),
    decorationThickness: fallback(
      this.decorationThickness,
      decorationThickness,
    ),
    debugLabel: fallback(this.debugLabel, debugLabel),
    fontFamily: fallback(this.fontFamily, fontFamily),
    fontFamilyFallback: fallback(this.fontFamilyFallback, fontFamilyFallback),
    overflow: fallback(this.overflow, overflow),
  );
}