build method

ThemeData build(
  1. Brightness brightness
)

Implementation

ThemeData build(Brightness brightness) {
  final colors = this.colors.copyWith(brightness: brightness);
  final sizes = this.sizes;
  final typography = this.typography.copyWith(colors: colors, sizes: sizes);
  final themeData = createThemeData(
    colors: colors,
    sizes: sizes,
    typography: typography,
  );
  final componentTheme = this.componentTheme.copyWith(
    colors: colors,
    sizes: sizes,
    typography: typography,
  );

  final colorScheme = ColorScheme(
    brightness: brightness,
    primary: colors.primary,
    onPrimary: colors.onPrimary,
    secondary: colors.secondary,
    onSecondary: colors.onSecondary,
    error: colors.error,
    onError: colors.onError,
    surface: colors.surface,
    onSurface: colors.onSurface,
    outline: colors.outline,
    shadow: colors.onSurface.darken(0.2),
    surfaceContainerHighest: colors.surfaceVariant,
  );

  final theme = ThemeData(
    useMaterial3: true,
    brightness: colorScheme.brightness,
    fontFamily: typography.bodyFontFamily,
    colorScheme: colorScheme,
    primaryColorLight: colorScheme.primary.withValues(alpha: .5),
    visualDensity: VisualDensity.adaptivePlatformDensity,
    scaffoldBackgroundColor: colors.background,
    dividerColor: colors.outline,
  );

  final textTheme = theme.textTheme
      .apply(
        fontFamily: typography.bodyFontFamily,
        displayColor: colors.textSecondary,
        bodyColor: colors.textPrimary,
      )
      .copyWith(
        displayLarge: typography.displayLarge,
        displayMedium: typography.displayMedium,
        displaySmall: typography.displaySmall,
        headlineLarge: typography.headlineLarge,
        headlineMedium: typography.headlineMedium,
        headlineSmall: typography.headlineSmall,
        titleLarge: typography.titleLarge,
        titleMedium: typography.titleMedium,
        titleSmall: typography.titleSmall,
        bodyLarge: typography.bodyLarge,
        bodyMedium: typography.bodyMedium,
        bodySmall: typography.bodySmall,
        labelLarge: typography.labelLarge,
        labelMedium: typography.labelMedium,
        labelSmall: typography.labelSmall,
      );

  return theme.copyWith(
    textTheme: textTheme,
    appBarTheme: themeData.appBarTheme,
    elevatedButtonTheme: themeData.elevatedButtonTheme,
    outlinedButtonTheme: themeData.outlinedButtonTheme,
    textButtonTheme: themeData.textButtonTheme,
    inputDecorationTheme: themeData.inputDecorationTheme,
    snackBarTheme: themeData.snackBarTheme,
    dividerTheme: themeData.dividerTheme,
    chipTheme: themeData.chipTheme,
    checkboxTheme: themeData.checkboxTheme,
    radioTheme: themeData.radioTheme,
    switchTheme: themeData.switchTheme,
    tooltipTheme: themeData.tooltipTheme,
    dialogTheme: themeData.dialogTheme,
    bottomSheetTheme: themeData.bottomSheetTheme,
    progressIndicatorTheme: themeData.progressIndicatorTheme,
    cardTheme: themeData.cardTheme,

    extensions: {
      sizes, // retrieve with: Theme.of(context).extension<VoSizes>()!
      colors, // retrieve with: Theme.of(context).extension<VoColors>()!
      typography, // retrieve with: Theme.of(context).extension<VoTypography>()!
      componentTheme, // retrieve with: Theme.of(context).extension<VoComponentTheme>()!
    },
  );
}