get method

ThemeData get({
  1. bool isDark = false,
})

Implementation

ThemeData get({
  bool isDark = false,
}) {
  final base = isDark ? ThemeData.dark() : ThemeData.light();

  late SoftUiThemeColors colors;
  if (isDark) {
    if (darkColors != null) {
      colors = darkColors!;
    } else {
      if (isGlassmorphism) {
        colors = SoftUiDarkColors.glassmorphism();
      } else if (isNeumorphism) {
        colors = SoftUiDarkColors.neumorphism();
      } else {
        colors = const SoftUiDarkColors();
      }
    }
  } else {
    if (lightColors != null) {
      colors = lightColors!;
    } else {
      if (isGlassmorphism) {
        colors = SoftUiLightColors.glassmorphism();
      } else if (isNeumorphism) {
        colors = SoftUiLightColors.neumorphism();
      } else {
        colors = const SoftUiLightColors();
      }
    }
  }

  late SoftUiThemeMetrics metrics;
  if (isGlassmorphism) {
    metrics =
        glassMetrics?.call(colors) ?? SoftUiMetrics.glassmorphism(colors);
  } else if (isNeumorphism) {
    metrics = neumoMetrics?.call(colors) ?? SoftUiMetrics.neumorphism(colors);
  } else {
    metrics = const SoftUiMetrics();
  }

  final theme = base.copyWith(
    brightness: isDark ? Brightness.dark : Brightness.light,
    colorScheme: ColorScheme.fromSeed(
      seedColor: colors.primary,
      brightness: isDark ? Brightness.dark : Brightness.light,
      primary: colors.primary,
      onPrimary: colors.onPrimary,
      secondary: colors.secondary,
      onSecondary: colors.onSecondary,
      tertiary: colors.tertiary,
      onTertiary: colors.onTertiary,
      surface: colors.surface,
      onSurface: colors.onSurface,
      outline: colors.border,
      shadow: colors.shadow,
      background: colors.background,
      onBackground: colors.text,
    ),
    primaryColor: colors.primary,
    primaryColorDark: colors.primary,
    primaryColorLight: colors.primary,
    dividerColor: colors.border,
    shadowColor: colors.shadow,
    scaffoldBackgroundColor: colors.background,
    iconTheme: IconThemeData(color: colors.text, size: metrics.icon),
    textTheme: GoogleFonts.interTextTheme(base.textTheme).copyWith(
      bodySmall: GoogleFonts.inter(
        fontSize: 12,
        fontWeight: FontWeight.normal,
        color: colors.text,
      ),
      bodyMedium: GoogleFonts.inter(
        fontSize: 14,
        fontWeight: FontWeight.normal,
        color: colors.text,
      ),
      bodyLarge: GoogleFonts.inter(
        fontSize: 16,
        fontWeight: FontWeight.normal,
        color: colors.text,
      ),
      titleSmall: GoogleFonts.inter(
        fontSize: 12,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
      titleMedium: GoogleFonts.inter(
        fontSize: 14,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
      titleLarge: GoogleFonts.inter(
        fontSize: 16,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
      headlineSmall: GoogleFonts.inter(
        fontSize: 16,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
      headlineMedium: GoogleFonts.inter(
        fontSize: 18,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
      headlineLarge: GoogleFonts.inter(
        fontSize: 24,
        fontWeight: FontWeight.bold,
        color: colors.text,
      ),
    ),
    extensions: [
      colors,
      metrics,
    ],
  );

  return theme;
}