applyToTextStyle static method

TextStyle applyToTextStyle(
  1. BuildContext context,
  2. FlyStyle style,
  3. TextStyle? baseStyle
)

Applies text style to a TextStyle using copyWith

Implementation

static TextStyle applyToTextStyle(
  BuildContext context,
  FlyStyle style,
  TextStyle? baseStyle,
) {
  final textStyle = resolve(context, style);
  final leadingValue = FlyLeadingUtils.resolve(context, style);
  final textDecoration = resolveTextDecoration(style.textDecoration);
  final fontWeight = FlyFontWeightUtils.resolve(context, style.fontWeight);
  final trackingValue = FlyTrackingUtils.resolve(context, style);
  final fontFamilies = FlyFontUtils.resolve(context, style.font);

  if (textStyle == null &&
      leadingValue == null &&
      textDecoration == null &&
      fontWeight == null &&
      trackingValue == null &&
      fontFamilies == null) {
    return baseStyle ?? const TextStyle();
  }

  // Start with base style or empty style
  TextStyle result = baseStyle ?? const TextStyle();

  // Apply text style if available
  if (textStyle != null) {
    result = textStyle.copyWith(
      color: baseStyle?.color,
      fontWeight: baseStyle?.fontWeight,
      fontStyle: baseStyle?.fontStyle,
      letterSpacing: baseStyle?.letterSpacing,
      wordSpacing: baseStyle?.wordSpacing,
      textBaseline: baseStyle?.textBaseline,
      height: baseStyle?.height,
      leadingDistribution: baseStyle?.leadingDistribution,
      locale: baseStyle?.locale,
      foreground: baseStyle?.foreground,
      background: baseStyle?.background,
      shadows: baseStyle?.shadows,
      fontFeatures: baseStyle?.fontFeatures,
      decoration: baseStyle?.decoration,
      decorationColor: baseStyle?.decorationColor,
      decorationStyle: baseStyle?.decorationStyle,
      decorationThickness: baseStyle?.decorationThickness,
      debugLabel: baseStyle?.debugLabel,
      fontFamily: baseStyle?.fontFamily,
      fontFamilyFallback: baseStyle?.fontFamilyFallback,
    );
  }

  // Apply leading if available
  if (leadingValue != null) {
    result = result.copyWith(height: leadingValue);
  }

  // Apply text decoration if available
  if (textDecoration != null) {
    result = result.copyWith(decoration: textDecoration);
  }

  // Apply font weight if available
  if (fontWeight != null) {
    result = result.copyWith(fontWeight: fontWeight);
  }

  // Apply tracking (letter spacing) if available
  if (trackingValue != null) {
    result = result.copyWith(letterSpacing: trackingValue);
  }

  // Apply font families if available
  if (fontFamilies != null) {
    result = result.copyWith(
      fontFamily: fontFamilies.primary ?? result.fontFamily,
      fontFamilyFallback: fontFamilies.fallback,
    );
  }

  return result;
}