apply method

Typeface apply({
  1. Chrome? chrome,
  2. TextStyle? background,
  3. TextStyle? foreground,
  4. TextStyle? primary,
  5. TextStyle? secondary,
  6. TextStyle? ascent,
  7. TextStyle? onPrimary,
  8. TextStyle? onSecondary,
  9. TextStyle? onAscent,
  10. TextStyle? success,
  11. TextStyle? error,
  12. TextStyle? warning,
  13. TextStyle? all,
})

Implementation

Typeface apply({
  Chrome? chrome,
  TextStyle? background,
  TextStyle? foreground,
  //...surface
  TextStyle? primary,
  TextStyle? secondary,
  TextStyle? ascent,
  //...on surface
  TextStyle? onPrimary,
  TextStyle? onSecondary,
  TextStyle? onAscent,
  //...extras
  TextStyle? success,
  TextStyle? error,
  TextStyle? warning,
  TextStyle? all,
}) {
  //...
  TextStyle merge(style, color) {
    //...
    style = style?.copyWith(colors: color);
    return style ?? TextStyle(color: color);
  }

  TextTheme apply(TextTheme original, TextStyle? other) {
    //...
    return original.apply(
      bodyColor: other?.color ?? all?.color,
      displayColor: other?.color ?? all?.color,
      fontFamily: other?.fontFamily ?? all?.fontFamily,
      decoration: other?.decoration ?? all?.decoration,
      decorationColor: other?.decorationColor ?? all?.decorationColor,
      decorationStyle: other?.decorationStyle ?? all?.decorationStyle,
    );
  }

  return Typeface(
    background: apply(this.background, merge(background, chrome?.background)),
    foreground: apply(this.foreground, merge(foreground, chrome?.foreground)),
    //...surface
    primary: apply(this.primary, merge(primary, chrome?.primary)),
    secondary: apply(this.secondary, merge(secondary, chrome?.secondary)),
    ascent: apply(this.ascent, merge(ascent, chrome?.ascent)),
    //...on surface
    onPrimary: apply(this.onPrimary, merge(onPrimary, chrome?.onPrimary)),
    onSecondary: apply(this.onSecondary, merge(onSecondary, chrome?.onSecondary)),
    onAscent: apply(this.onAscent, merge(onAscent, chrome?.onAscent)),
    //...extras
    success: apply(this.success, merge(success, chrome?.success)),
    error: apply(this.error, merge(error, chrome?.error)),
    warning: apply(this.warning, merge(warning, chrome?.warning)),
  );
}