builder static method

ThemeData builder(
  1. BuildContext context, {
  2. Brightness? brightness,
  3. Brightness? primaryBrightness,
  4. Brightness? bottomBrightness,
  5. String? fontFamily,
  6. TextTheme? textTheme,
  7. IconThemeData? iconTheme,
  8. AppBarTheme? appBarTheme,
  9. ButtonStyle? elevatedButtonStyle,
  10. ButtonStyle? outlinedButtonStyle,
  11. ButtonStyle? textButtonStyle,
  12. Color secondaryColorLight = kSecondaryColor,
  13. Color primarySwatchLight = kPrimarySwatch,
  14. Color backgroundLight = kBackgroundLight,
  15. Color canvasColorLight = kCanvasColorLight,
  16. Color primaryBackgroundLight = kPrimaryBackgroundLight,
  17. Color bottomBackgroundLight = kPrimaryBackgroundLight,
  18. Color bottomForegroundLight = kSecondaryColor,
  19. Color secondaryColorDark = kSecondaryColor,
  20. Color primarySwatchDark = kPrimarySwatch,
  21. Color backgroundDark = kBackgroundDark,
  22. Color canvasColorDark = kCanvasColorDark,
  23. Color primaryBackgroundDark = kPrimaryBackgroundDark,
  24. Color bottomBackgroundDark = kPrimaryBackgroundDark,
  25. Color bottomForegroundDark = kSecondaryColor,
})

Implementation

static ThemeData builder(
  BuildContext context, {
  Brightness? brightness,
  Brightness? primaryBrightness,
  Brightness? bottomBrightness,
  String? fontFamily,
  TextTheme? textTheme,
  IconThemeData? iconTheme,
  AppBarTheme? appBarTheme,
  ButtonStyle? elevatedButtonStyle,
  ButtonStyle? outlinedButtonStyle,
  ButtonStyle? textButtonStyle,
  // light theme attributes
  Color secondaryColorLight = kSecondaryColor,
  Color primarySwatchLight = kPrimarySwatch,
  Color backgroundLight = kBackgroundLight,
  Color canvasColorLight = kCanvasColorLight,
  Color primaryBackgroundLight = kPrimaryBackgroundLight,
  Color bottomBackgroundLight = kPrimaryBackgroundLight,
  Color bottomForegroundLight = kSecondaryColor,
  // dark theme attributes
  Color secondaryColorDark = kSecondaryColor,
  Color primarySwatchDark = kPrimarySwatch,
  Color backgroundDark = kBackgroundDark,
  Color canvasColorDark = kCanvasColorDark,
  Color primaryBackgroundDark = kPrimaryBackgroundDark,
  Color bottomBackgroundDark = kPrimaryBackgroundDark,
  Color bottomForegroundDark = kSecondaryColor,
}) {
  final _brightness = brightness ?? GetTheme.brightness(context);
  final _primaryBrightness = primaryBrightness ?? _brightness;
  final _bottomBrightness = bottomBrightness ?? _brightness;
  final isDark = _brightness == Brightness.dark;
  final isDarkPrimary = _primaryBrightness == Brightness.dark;
  final isDarkBottom = _bottomBrightness == Brightness.dark;
  final theme = ThemeData(brightness: _brightness);
  final bottomTheme = ThemeData(brightness: _bottomBrightness);
  final _secondaryColor = isDark ? secondaryColorDark : secondaryColorLight;
  final _primaryForeground =
      isDarkPrimary ? secondaryColorDark : secondaryColorLight;
  final _bottomForeground =
      isDarkBottom ? bottomForegroundDark : bottomForegroundLight;
  final _primarySwatch = isDark ? primarySwatchDark : primarySwatchLight;
  final _primaryBackground =
      isDark ? primaryBackgroundDark : primaryBackgroundLight;
  final _bottomBackground =
      isDarkBottom ? bottomBackgroundDark : bottomBackgroundLight;
  final _iconTheme = IconThemeData(
    color: iconTheme?.color ?? _secondaryColor,
    opacity: iconTheme?.opacity,
    size: iconTheme?.size ?? 24.0,
  );
  final _primaryIconTheme = IconThemeData(
    color: appBarTheme?.iconTheme?.color ?? _primaryForeground,
    opacity: appBarTheme?.iconTheme?.opacity,
    size: appBarTheme?.iconTheme?.size ?? 24.0,
  );
  return ThemeData(
    colorScheme: ColorScheme.fromSwatch(
      primarySwatch: $cast(_primarySwatch),
      accentColor: _secondaryColor,
      brightness: _brightness,
      backgroundColor: isDark ? backgroundDark : backgroundLight,
    ),
    primaryColor: _primaryBackground,
    brightness: _brightness,
    backgroundColor: isDark ? backgroundDark : backgroundLight,
    canvasColor: isDark ? canvasColorDark : canvasColorLight,
    scaffoldBackgroundColor: isDark ? canvasColorDark : canvasColorLight,
    bottomAppBarColor: _bottomBackground,
    hintColor: theme.hintColor.hinted,
    primaryIconTheme: _primaryIconTheme,
    iconTheme: _iconTheme,
    fontFamily: fontFamily,
    textTheme: textTheme,
    listTileTheme: ListTileThemeData(iconColor: _secondaryColor),
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(
        elevation:
            elevatedButtonStyle?.elevation ?? GetButton.defaultElevation(),
        shape: elevatedButtonStyle?.shape ?? GetButton.defaultShape(),
        minimumSize: elevatedButtonStyle?.minimumSize,
        padding: elevatedButtonStyle?.padding,
        side: elevatedButtonStyle?.side,
        backgroundColor: elevatedButtonStyle?.backgroundColor,
        foregroundColor: elevatedButtonStyle?.foregroundColor,
        textStyle: elevatedButtonStyle?.textStyle,
        visualDensity: elevatedButtonStyle?.visualDensity,
        tapTargetSize: elevatedButtonStyle?.tapTargetSize,
      ),
    ),
    outlinedButtonTheme: OutlinedButtonThemeData(
      style: ButtonStyle(
        shape: outlinedButtonStyle?.shape ?? GetButton.defaultShape(),
        side: outlinedButtonStyle?.side ??
            GetButton.defaultSide(_secondaryColor),
        elevation: outlinedButtonStyle?.elevation,
        minimumSize: outlinedButtonStyle?.minimumSize,
        padding: outlinedButtonStyle?.padding,
        backgroundColor: outlinedButtonStyle?.backgroundColor,
        foregroundColor: outlinedButtonStyle?.foregroundColor,
        textStyle: outlinedButtonStyle?.textStyle,
        visualDensity: outlinedButtonStyle?.visualDensity,
        tapTargetSize: outlinedButtonStyle?.tapTargetSize,
      ),
    ),
    textButtonTheme: TextButtonThemeData(
      style: ButtonStyle(
        shape: textButtonStyle?.shape,
        side: textButtonStyle?.side,
        elevation: textButtonStyle?.elevation,
        minimumSize: textButtonStyle?.minimumSize,
        padding: textButtonStyle?.padding,
        backgroundColor: textButtonStyle?.backgroundColor,
        foregroundColor: textButtonStyle?.foregroundColor,
        textStyle: textButtonStyle?.textStyle,
        visualDensity: textButtonStyle?.visualDensity,
        tapTargetSize: textButtonStyle?.tapTargetSize,
      ),
    ),
    buttonTheme: ButtonThemeData(
      textTheme: ButtonTextTheme.primary,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(5),
      ),
    ),
    appBarTheme: AppBarTheme(
      elevation: appBarTheme?.elevation ?? 1.0,
      toolbarHeight: appBarTheme?.toolbarHeight ?? toolbarHeight,
      shadowColor: appBarTheme?.shadowColor ?? Colors.black,
      backgroundColor: appBarTheme?.backgroundColor ?? _primaryBackground,
      titleTextStyle: TextStyle(
        fontSize: appBarTheme?.titleTextStyle?.fontSize ?? 18,
        color:
            appBarTheme?.titleTextStyle?.color ?? _primaryBackground.contrast,
        fontWeight:
            appBarTheme?.titleTextStyle?.fontWeight ?? FontWeight.w600,
        fontFamily: appBarTheme?.titleTextStyle?.fontFamily ?? fontFamily,
      ),
      toolbarTextStyle: TextStyle(
        fontSize: appBarTheme?.toolbarTextStyle?.fontSize ?? 14,
        color: appBarTheme?.toolbarTextStyle?.color ??
            _primaryBackground.contrast.activated,
        fontFamily: appBarTheme?.toolbarTextStyle?.fontFamily ?? fontFamily,
      ),
      foregroundColor:
          appBarTheme?.foregroundColor ?? _primaryBackground.contrast,
      iconTheme: _primaryIconTheme,
      actionsIconTheme: appBarTheme?.actionsIconTheme ?? _primaryIconTheme,
      systemOverlayStyle: SystemUiOverlayStyle(
        // systemNavigationBarDividerColor: _bottomBackground,
        // systemNavigationBarIconBrightness: _bottomBrightness.inverse,
        // systemNavigationBarColor: _bottomBackground,
        systemNavigationBarDividerColor:
            appBarTheme?.systemOverlayStyle?.systemNavigationBarDividerColor,
        systemNavigationBarIconBrightness: appBarTheme
            ?.systemOverlayStyle?.systemNavigationBarIconBrightness,
        systemNavigationBarColor:
            appBarTheme?.systemOverlayStyle?.systemNavigationBarColor,
        systemNavigationBarContrastEnforced: appBarTheme
            ?.systemOverlayStyle?.systemNavigationBarContrastEnforced,
        systemStatusBarContrastEnforced:
            appBarTheme?.systemOverlayStyle?.systemStatusBarContrastEnforced,
        statusBarBrightness:
            appBarTheme?.systemOverlayStyle?.statusBarBrightness ??
                _primaryBrightness,
        statusBarIconBrightness:
            appBarTheme?.systemOverlayStyle?.statusBarIconBrightness ??
                _primaryBrightness.inverse,
        statusBarColor: appBarTheme?.systemOverlayStyle?.statusBarColor ??
            Colors.transparent,
      ),
    ),
    bottomAppBarTheme: BottomAppBarTheme(
      elevation: 4,
      color: _bottomBackground,
      shape: const CircularNotchedRectangle(),
    ),
    bottomNavigationBarTheme: BottomNavigationBarThemeData(
      elevation: 4,
      selectedLabelStyle: TextStyle(
        fontSize: 10,
        fontFamily: fontFamily,
        height: 1.6,
      ),
      unselectedLabelStyle: TextStyle(
        fontSize: 9.8,
        fontFamily: fontFamily,
        height: 1.6,
      ),
      type: BottomNavigationBarType.fixed,
      showSelectedLabels: true,
      showUnselectedLabels: true,
      backgroundColor: _bottomBackground,
      selectedItemColor: _bottomForeground,
      unselectedItemColor: bottomTheme.hintColor.hinted,
      selectedIconTheme: const IconThemeData(size: 20),
      unselectedIconTheme: const IconThemeData(size: 20),
    ),
    snackBarTheme: SnackBarThemeData(
      backgroundColor: _bottomBackground,
    ),
    switchTheme: const SwitchThemeData(
      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      splashRadius: 16,
    ),
  );
}