getThemeData static method

ThemeData getThemeData(
  1. Brightness brightness,
  2. ThemeProvider themeProvider,
  3. ColorProvider colorProvider(),
  4. TextContrastProvider textContrastProvider(),
)

Implementation

static ThemeData getThemeData(
  Brightness brightness,
  ThemeProvider themeProvider,
  ColorProvider Function() colorProvider,
  TextContrastProvider Function() textContrastProvider,
) {
  final bool lightTheme = brightness == Brightness.light;
  ColorScheme myColorScheme;

  if (lightTheme) {
    myColorScheme = lightColorScheme;
  } else {
    if (themeProvider.currentTheme == THEME_AMOLED) {
      final ColorProvider colorNotifier = colorProvider();

      myColorScheme = trueDarkColorScheme.copyWith(
        primary: getColorValue(colorNotifier.currentColor),
        secondary: getShade(
          getColorValue(colorNotifier.currentColor),
          darker: true,
          value: SECONDARY_COLOR_SHADE_VALUE,
        ),
      );
    } else {
      myColorScheme = darkColorScheme;
    }
  }

  final SmoothColorsThemeExtension smoothExtension =
      SmoothColorsThemeExtension.defaultValues(lightTheme);

  final TextTheme textTheme = brightness == Brightness.dark
      ? getTextTheme(themeProvider, textContrastProvider)
      : _TEXT_THEME;

  return ThemeData(
    fontFamily: 'OpenSans',
    primaryColor: smoothExtension.primaryBlack,
    extensions: <ThemeExtension<dynamic>>[smoothExtension],
    colorScheme: myColorScheme,
    canvasColor: themeProvider.currentTheme == THEME_AMOLED
        ? myColorScheme.surface
        : null,
    scaffoldBackgroundColor:
        themeProvider.currentTheme == THEME_DARK ||
            (!lightTheme && themeProvider.currentTheme != THEME_AMOLED)
        ? const Color(0xFF303030)
        : null,
    shadowColor: brightness == Brightness.light
        ? Colors.black54
        : Colors.white12,
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(
        backgroundColor: WidgetStateProperty.resolveWith<Color?>(
          (Set<WidgetState> states) => states.contains(WidgetState.disabled)
              ? Colors.grey
              : myColorScheme.primary,
        ),
        foregroundColor: WidgetStateProperty.resolveWith<Color?>(
          (Set<WidgetState> states) => states.contains(WidgetState.disabled)
              ? Colors.white
              : myColorScheme.onPrimary,
        ),
        iconColor: WidgetStateProperty.all<Color>(myColorScheme.onPrimary),
      ),
    ),
    floatingActionButtonTheme: FloatingActionButtonThemeData(
      backgroundColor: lightTheme
          ? smoothExtension.primaryDark
          : myColorScheme.primary,
      foregroundColor: myColorScheme.onPrimary,
    ),
    textTheme: textTheme,
    appBarTheme: AppBarTheme(
      centerTitle: false,
      backgroundColor: myColorScheme.surface,
      foregroundColor: myColorScheme.onSurface,
      systemOverlayStyle: SystemUiOverlayStyle.light,
      titleTextStyle: textTheme.titleLarge,
    ),
    dividerTheme: const DividerThemeData(
      color: Color(0xFFECECEC),
      space: 1.0,
    ),
    dividerColor: const Color(0xFFDFDFDF),
    inputDecorationTheme: InputDecorationTheme(
      fillColor: myColorScheme.secondary,
    ),
    iconTheme: IconThemeData(color: myColorScheme.onSurface),
    snackBarTheme: SnackBarThemeData(
      contentTextStyle: _TEXT_THEME.bodyMedium?.copyWith(
        color: Colors.white,
        fontWeight: FontWeight.w500,
      ),
      actionTextColor: Colors.white,
      actionBackgroundColor: smoothExtension.primaryDark,
      backgroundColor: smoothExtension.primaryBlack,
    ),
    bannerTheme: MaterialBannerThemeData(
      contentTextStyle: TextStyle(color: myColorScheme.onSecondary),
      backgroundColor: myColorScheme.secondary,
    ),
    checkboxTheme: CheckboxThemeData(
      fillColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (states.contains(WidgetState.disabled)) {
          return null;
        }
        if (states.contains(WidgetState.selected)) {
          return lightTheme
              ? smoothExtension.primarySemiDark
              : smoothExtension.primaryNormal;
        }
        return null;
      }),
      side: BorderSide(
        color: lightTheme
            ? smoothExtension.primaryBlack
            : smoothExtension.primarySemiDark,
        width: 2.0,
      ),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3.0)),
      checkColor: const WidgetStatePropertyAll<Color>(Colors.white),
    ),
    radioTheme: RadioThemeData(
      fillColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (states.contains(WidgetState.disabled)) {
          return null;
        }
        if (states.contains(WidgetState.selected)) {
          return myColorScheme.primary;
        }
        return null;
      }),
    ),
    switchTheme: SwitchThemeData(
      thumbColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (states.contains(WidgetState.selected)) {
          if (lightTheme) {
            return smoothExtension.primaryDark;
          } else {
            return smoothExtension.primarySemiDark;
          }
        } else if (states.contains(WidgetState.disabled)) {
          if (lightTheme) {
            return const Color(0xFFC2B5B0);
          } else {
            return smoothExtension.primaryNormal;
          }
        } else {
          return null;
        }
      }),
      trackColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (lightTheme) {
          return smoothExtension.primaryMedium;
        } else {
          return const Color(0xFFEDE0DB);
        }
      }),
    ),
  );
}