import 'package:PiliPlus/common/constants.dart'; import 'package:PiliPlus/main.dart'; import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:flex_seed_scheme/flex_seed_scheme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; abstract class ThemeUtils { static ThemeData getThemeData({ required ColorScheme colorScheme, required bool isDynamic, bool isDark = false, required FlexSchemeVariant variant, }) { final appFontWeight = Pref.appFontWeight.clamp( -1, FontWeight.values.length - 1, ); final fontWeight = appFontWeight == -1 ? null : FontWeight.values[appFontWeight]; late final textStyle = TextStyle(fontWeight: fontWeight); ThemeData themeData = ThemeData( colorScheme: colorScheme, useMaterial3: true, textTheme: fontWeight == null ? null : TextTheme( displayLarge: textStyle, displayMedium: textStyle, displaySmall: textStyle, headlineLarge: textStyle, headlineMedium: textStyle, headlineSmall: textStyle, titleLarge: textStyle, titleMedium: textStyle, titleSmall: textStyle, bodyLarge: textStyle, bodyMedium: textStyle, bodySmall: textStyle, labelLarge: textStyle, labelMedium: textStyle, labelSmall: textStyle, ), tabBarTheme: fontWeight == null ? null : TabBarThemeData(labelStyle: textStyle), appBarTheme: AppBarTheme( elevation: 0, titleSpacing: 0, centerTitle: false, scrolledUnderElevation: 0, backgroundColor: colorScheme.surface, titleTextStyle: TextStyle( fontSize: 16, color: colorScheme.onSurface, fontWeight: fontWeight, ), ), navigationBarTheme: NavigationBarThemeData( surfaceTintColor: isDynamic ? colorScheme.onSurfaceVariant : null, ), snackBarTheme: SnackBarThemeData( actionTextColor: colorScheme.primary, backgroundColor: colorScheme.secondaryContainer, closeIconColor: colorScheme.secondary, contentTextStyle: TextStyle(color: colorScheme.onSecondaryContainer), elevation: 20, ), popupMenuTheme: PopupMenuThemeData( surfaceTintColor: isDynamic ? colorScheme.onSurfaceVariant : null, ), cardTheme: CardThemeData( elevation: 1, margin: EdgeInsets.zero, surfaceTintColor: isDynamic ? colorScheme.onSurfaceVariant : isDark ? colorScheme.onSurfaceVariant : null, shadowColor: Colors.transparent, ), progressIndicatorTheme: ProgressIndicatorThemeData( // ignore: deprecated_member_use year2023: false, refreshBackgroundColor: colorScheme.onSecondary, ), dialogTheme: DialogThemeData( titleTextStyle: TextStyle( fontSize: 18, color: colorScheme.onSurface, fontWeight: fontWeight, ), backgroundColor: colorScheme.surface, ), bottomSheetTheme: BottomSheetThemeData( backgroundColor: colorScheme.surface, shape: const RoundedRectangleBorder( borderRadius: StyleString.bottomSheetRadius, ), ), // ignore: deprecated_member_use sliderTheme: const SliderThemeData(year2023: false), tooltipTheme: TooltipThemeData( textStyle: const TextStyle( color: Colors.white, fontSize: 14, ), decoration: BoxDecoration( color: Colors.grey[700]!.withValues(alpha: 0.9), borderRadius: const BorderRadius.all(Radius.circular(4)), ), ), cupertinoOverrideTheme: CupertinoThemeData( selectionHandleColor: colorScheme.primary, ), switchTheme: const SwitchThemeData( thumbIcon: WidgetStateProperty.fromMap( { WidgetState.selected: Icon(Icons.done), WidgetState.any: null, }, ), ), ); if (isDark) { if (Pref.isPureBlackTheme) { themeData = darkenTheme(themeData); } if (Pref.darkVideoPage) { MyApp.darkThemeData = themeData; } } return themeData; } static ThemeData darkenTheme(ThemeData themeData) { final colorScheme = themeData.colorScheme; final color = colorScheme.surfaceContainerHighest.darken(0.7); return themeData.copyWith( scaffoldBackgroundColor: Colors.black, appBarTheme: themeData.appBarTheme.copyWith( backgroundColor: Colors.black, ), cardTheme: themeData.cardTheme.copyWith( color: Colors.black, ), dialogTheme: themeData.dialogTheme.copyWith( backgroundColor: color, ), bottomSheetTheme: themeData.bottomSheetTheme.copyWith( backgroundColor: color, ), bottomNavigationBarTheme: themeData.bottomNavigationBarTheme.copyWith( backgroundColor: color, ), navigationBarTheme: themeData.navigationBarTheme.copyWith( backgroundColor: color, ), navigationRailTheme: themeData.navigationRailTheme.copyWith( backgroundColor: Colors.black, ), colorScheme: colorScheme.copyWith( primary: colorScheme.primary.darken(0.1), onPrimary: colorScheme.onPrimary.darken(0.1), primaryContainer: colorScheme.primaryContainer.darken(0.1), onPrimaryContainer: colorScheme.onPrimaryContainer.darken(0.1), inversePrimary: colorScheme.inversePrimary.darken(0.1), secondary: colorScheme.secondary.darken(0.1), onSecondary: colorScheme.onSecondary.darken(0.1), secondaryContainer: colorScheme.secondaryContainer.darken(0.1), onSecondaryContainer: colorScheme.onSecondaryContainer.darken(0.1), error: colorScheme.error.darken(0.1), surface: Colors.black, onSurface: colorScheme.onSurface.darken(0.15), surfaceTint: colorScheme.surfaceTint.darken(), inverseSurface: colorScheme.inverseSurface.darken(), onInverseSurface: colorScheme.onInverseSurface.darken(), surfaceContainer: colorScheme.surfaceContainer.darken(), surfaceContainerHigh: colorScheme.surfaceContainerHigh.darken(), surfaceContainerHighest: colorScheme.surfaceContainerHighest.darken( 0.4, ), ), ); } }