ThemeData.lerp constructor

ThemeData.lerp(
  1. ThemeData a,
  2. ThemeData b,
  3. double t
)

The theme t of the way from a to b, for a cross-fade: a at 0, b at 1. Each slot and token blends as a StyleTween has it (RGB colors channel by channel, others switching halfway), shadeAlpha as a number; the brightness switches halfway. The tokens are blended as they are in a and b, not derived again.

Implementation

factory ThemeData.lerp(ThemeData a, ThemeData b, double t) {
  if (identical(a, b) || t == 0) {
    return a;
  }
  if (t == 1) {
    return b;
  }
  Style style(Style x, Style y) => StyleTween(begin: x, end: y).transform(t);
  return ThemeData(
    brightness: t < 0.5 ? a.brightness : b.brightness,
    background: style(a.background, b.background),
    surface: style(a.surface, b.surface),
    text: style(a.text, b.text),
    muted: style(a.muted, b.muted),
    primary: style(a.primary, b.primary),
    accent: style(a.accent, b.accent),
    border: style(a.border, b.border),
    selection: style(a.selection, b.selection),
    error: style(a.error, b.error),
    warning: style(a.warning, b.warning),
    success: style(a.success, b.success),
    info: style(a.info, b.info),
    chrome: style(a.chrome, b.chrome),
    well: style(a.well, b.well),
    faint: style(a.faint, b.faint),
    dim: style(a.dim, b.dim),
    selectionIdle: style(a.selectionIdle, b.selectionIdle),
    hover: style(a.hover, b.hover),
    onPrimary: style(a.onPrimary, b.onPrimary),
    shade: style(a.shade, b.shade),
    shadeAlpha: a.shadeAlpha + (b.shadeAlpha - a.shadeAlpha) * t,
    palette: t < 0.5 ? a.palette : b.palette,
    pointerMode: t < 0.5 ? a.pointerMode : b.pointerMode,
    glyphs: Glyphs.lerp(a.glyphs, b.glyphs, t),
  );
}