resolve method

  1. @override
RSwitchListTileResolvedTokens resolve({
  1. required BuildContext context,
  2. required RSwitchListTileSpec spec,
  3. required Set<WidgetState> states,
  4. BoxConstraints? constraints,
  5. RenderOverrides? overrides,
})

Implementation

@override
RSwitchListTileResolvedTokens resolve({
  required BuildContext context,
  required RSwitchListTileSpec spec,
  required Set<WidgetState> states,
  BoxConstraints? constraints,
  RenderOverrides? overrides,
}) {
  final motionTheme =
      HeadlessThemeProvider.of(context)?.capability<HeadlessMotionTheme>() ??
          HeadlessMotionTheme.material;

  final theme = Theme.of(context);
  final scheme = colorScheme ?? theme.colorScheme;
  final text = textTheme ?? theme.textTheme;
  final useMaterial3 = theme.useMaterial3;
  final q = HeadlessWidgetStateQuery(states);

  final tileOverrides = overrides?.get<RSwitchListTileOverrides>();

  final baseTitle = useMaterial3
      ? (text.bodyLarge ?? const TextStyle(fontSize: 16))
      : (text.titleMedium ?? const TextStyle(fontSize: 16));
  final baseSubtitle = useMaterial3
      ? (text.bodyMedium ?? const TextStyle(fontSize: 14))
      : (text.bodyMedium ?? const TextStyle(fontSize: 14))
          .copyWith(color: text.bodySmall?.color);

  Color? titleColor = useMaterial3 ? scheme.onSurface : null;
  Color? subtitleColor =
      useMaterial3 ? scheme.onSurfaceVariant : baseSubtitle.color;

  if (q.isDisabled) {
    titleColor = scheme.onSurface.withValues(alpha: 0.38);
    subtitleColor = scheme.onSurface.withValues(alpha: 0.38);
  } else if (q.isSelected) {
    final selectedColor = spec.selectedColor ?? scheme.primary;
    titleColor = selectedColor;
    subtitleColor = selectedColor;
  }

  final titleStyle =
      (tileOverrides?.titleStyle ?? baseTitle).copyWith(color: titleColor);
  final subtitleStyle =
      (tileOverrides?.subtitleStyle ?? baseSubtitle).copyWith(
    color: subtitleColor,
  );

  final minHeight = _resolveMinHeight(spec, constraints);
  final defaultPadding = useMaterial3
      ? const EdgeInsetsDirectional.only(start: 16, end: 24)
      : const EdgeInsets.symmetric(horizontal: 16);
  final defaultVerticalGap = useMaterial3 ? 2.0 : 4.0;

  return RSwitchListTileResolvedTokens(
    contentPadding: tileOverrides?.contentPadding ??
        spec.contentPadding ??
        defaultPadding,
    minHeight: tileOverrides?.minHeight ?? minHeight,
    horizontalGap: tileOverrides?.horizontalGap ?? 16,
    verticalGap: tileOverrides?.verticalGap ?? defaultVerticalGap,
    titleStyle: titleStyle,
    subtitleStyle: subtitleStyle,
    disabledOpacity: tileOverrides?.disabledOpacity ?? 1.0,
    pressOverlayColor: tileOverrides?.pressOverlayColor ??
        scheme.primary.withValues(alpha: 0.12),
    pressOpacity: tileOverrides?.pressOpacity ?? 1.0,
    motion: tileOverrides?.motion ??
        RSwitchListTileMotionTokens(
          stateChangeDuration: motionTheme.button.stateChangeDuration,
        ),
  );
}