buildThemeData method

ThemeData buildThemeData(
  1. BuildContext context
)

Build a ThemeData to wrap the checkout widget so child screens automatically inherit brand colors via Theme.of(context).

Resolution order for each color:

  1. value passed in this LokotroPayThemeConfig
  2. host app's Theme.of(context).colorScheme.*
  3. minimal neutral default (white surface, slate text)

Implementation

ThemeData buildThemeData(BuildContext context) {
  final hostTheme = Theme.of(context);
  final hostScheme = hostTheme.colorScheme;
  final effective = getEffectiveTheme(MediaQuery.platformBrightnessOf(context));
  final isDark = effective.theme == LokotroPayTheme.dark;

  final primary = effective.primaryColor ?? hostScheme.primary;
  final secondary = effective.secondaryColor ?? hostScheme.secondary;
  final tertiary = effective.tertiaryColor ?? hostScheme.tertiary;
  final surface = effective.backgroundColor ??
      (isDark ? const Color(0xFF0F172A) : Colors.white);
  final onSurface = effective.textColor ??
      (isDark ? const Color(0xFFF8FAFC) : const Color(0xFF0F172A));
  final onSurfaceVariant = effective.secondaryTextColor ??
      (isDark ? const Color(0xFFCBD5E1) : const Color(0xFF64748B));
  final outline = effective.borderColor ??
      (isDark ? const Color(0xFF334155) : const Color(0xFFE2E8F0));

  final colorScheme = (isDark ? const ColorScheme.dark() : const ColorScheme.light()).copyWith(
    primary: primary,
    secondary: secondary,
    tertiary: tertiary,
    surface: surface,
    surfaceContainer: effective.surfaceColor ??
        (isDark ? const Color(0xFF1E293B) : const Color(0xFFF7F8FA)),
    surfaceContainerHighest: effective.surfaceColor ??
        (isDark ? const Color(0xFF1E293B) : const Color(0xFFF1F5F9)),
    onSurface: onSurface,
    onSurfaceVariant: onSurfaceVariant,
    outline: outline,
    outlineVariant: outline.withValues(alpha: 0.5),
    error: effective.errorColor ?? LokotroPayColors.error,
  );

  return ThemeData(
    useMaterial3: true,
    brightness: isDark ? Brightness.dark : Brightness.light,
    colorScheme: colorScheme,
    scaffoldBackgroundColor: surface,
    textTheme: getTextTheme(onSurface),
  );
}