BaseThemeData constructor

BaseThemeData({
  1. Brightness? brightness,
  2. double? appBarHeight,
  3. bool appBarBackdropFilter = true,
  4. bool appBarTransitionBetweenRoutes = true,
  5. ThemeData? materialTheme,
  6. ThemeData? materialDarkTheme,
  7. ThemeData? materialHighContrastTheme,
  8. ThemeData? materialHighContrastDarkTheme,
  9. CupertinoThemeData? cupertinoTheme,
  10. bool useMaterial3 = true,
  11. bool routeFullscreenGackGesture = false,
  12. Color? sectionDividerColor,
  13. Color? tileBackgroundColor,
  14. BasePlatformMode? platformMode = const BasePlatformMode(),
  15. bool withoutSplashOnCupertino = true,
  16. BaseParam? baseParam,
})

Implementation

factory BaseThemeData({
  Brightness? brightness,
  double? appBarHeight,
  bool appBarBackdropFilter = true,
  bool appBarTransitionBetweenRoutes = true,
  ThemeData? materialTheme,
  ThemeData? materialDarkTheme,
  ThemeData? materialHighContrastTheme,
  ThemeData? materialHighContrastDarkTheme,
  CupertinoThemeData? cupertinoTheme,
  bool useMaterial3 = true,
  bool routeFullscreenGackGesture = false,
  Color? sectionDividerColor,
  Color? tileBackgroundColor,
  BasePlatformMode? platformMode = const BasePlatformMode(),
  bool withoutSplashOnCupertino = true,
  BaseParam? baseParam,
}) {
  brightness ??= Brightness.light;
  final bool isDark = brightness == Brightness.dark;

  // Create default Material 3 themes if not provided and useMaterial3 is true
  if (useMaterial3 && materialTheme == null) {
    materialTheme = ThemeData(
      brightness: Brightness.light,
      colorScheme: ColorScheme.fromSeed(
        seedColor: Colors.blue,
        brightness: Brightness.light,
      ),
      // Ensure proper default text styling to prevent yellow underlines
      textTheme: ThemeData.light().textTheme,
    );
  }

  if (useMaterial3 && materialDarkTheme == null) {
    materialDarkTheme = ThemeData(
      brightness: Brightness.dark,
      colorScheme: ColorScheme.fromSeed(
        seedColor: Colors.blue,
        brightness: Brightness.dark,
      ),
      // Ensure proper default text styling to prevent yellow underlines
      textTheme: ThemeData.dark().textTheme,
    );
  }

  // Ensure any provided themes have proper text styling
  if (materialTheme != null) {
    // Only modify if the theme doesn't already have a complete textTheme
    if (materialTheme.textTheme.bodyMedium?.decoration != TextDecoration.none) {
      materialTheme = materialTheme.copyWith(
        textTheme: ThemeData.light().textTheme,
      );
    }
  }

  if (materialDarkTheme != null) {
    // Only modify if the theme doesn't already have a complete textTheme
    if (materialDarkTheme.textTheme.bodyMedium?.decoration != TextDecoration.none) {
      materialDarkTheme = materialDarkTheme.copyWith(
        textTheme: ThemeData.dark().textTheme,
      );
    }
  }

  return BaseThemeData.raw(
    brightness: brightness,
    appBarHeight: appBarHeight,
    appBarBackdropFilter: appBarBackdropFilter,
    appBarTransitionBetweenRoutes: appBarTransitionBetweenRoutes,
    materialTheme: materialTheme,
    materialDarkTheme: materialDarkTheme,
    materialHighContrastTheme: materialHighContrastTheme,
    materialHighContrastDarkTheme: materialHighContrastDarkTheme,
    cupertinoTheme: cupertinoTheme,
    useMaterial3: useMaterial3,
    routeFullscreenGackGesture: routeFullscreenGackGesture,
    sectionDividerColor: sectionDividerColor ?? (isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000)),
    tileBackgroundColor: tileBackgroundColor,
    platformMode: platformMode,
    withoutSplashOnCupertino: withoutSplashOnCupertino,
    baseParam: baseParam,
  );
}