getReferenceValue<T> function

T getReferenceValue<T>(
  1. MixToken<T> token
)

Creates the appropriate token reference for the given token.

Returns a reference that implements the target type, allowing the token to be used wherever the type is expected.

Throws UnsupportedError if T is not in the supported reference set. Concrete MixToken subclasses (ColorToken, SpaceToken, etc.) override call() directly and never hit this fallback; custom token authors must either pick one of the supported types or override call() themselves.

Implementation

T getReferenceValue<T>(MixToken<T> token) {
  final prop = Prop.token(token);

  final Object ref = switch (T) {
    const (Color) => ColorRef(prop as Prop<Color>),
    const (double) => DoubleRef.token(token as MixToken<double>),
    const (Radius) => RadiusRef(prop as Prop<Radius>),
    const (Shadow) => ShadowRef(prop as Prop<Shadow>),
    const (BoxShadow) => BoxShadowRef(prop as Prop<BoxShadow>),
    const (TextStyle) => TextStyleRef(prop as Prop<TextStyle>),
    const (Breakpoint) => BreakpointRef(token as BreakpointToken),
    const (BorderSide) => BorderSideRef(prop as Prop<BorderSide>),
    const (FontWeight) => FontWeightRef(prop as Prop<FontWeight>),
    const (Duration) => DurationRef(prop as Prop<Duration>),
    const (List<Shadow>) => ShadowListRef(prop as Prop<List<Shadow>>),
    const (List<BoxShadow>) => BoxShadowListRef(prop as Prop<List<BoxShadow>>),
    _ => throw UnsupportedError(
      'No token reference is registered for MixToken<$T> "${token.name}". '
      'Either pick one of the supported token value types (Color, double, '
      'Radius, Shadow, BoxShadow, TextStyle, Breakpoint, BorderSide, '
      'FontWeight, Duration, List<Shadow>, List<BoxShadow>) or override '
      'MixToken<$T>.call() in your subclass to return a custom reference.',
    ),
  };

  return ref as T;
}