Rain/lib/theme/theme.dart

160 lines
4.4 KiB
Dart
Raw Normal View History

2023-06-17 20:57:57 +03:00
import 'package:flutter/material.dart';
2024-07-09 23:03:40 +03:00
import 'package:flutter/services.dart';
2023-07-12 20:52:25 +03:00
import 'package:google_fonts/google_fonts.dart';
2024-05-18 21:58:53 +03:00
import 'package:dynamic_color/dynamic_color.dart';
2023-06-17 20:57:57 +03:00
2025-05-28 17:42:15 +03:00
final ThemeData baseLight = ThemeData.light(useMaterial3: true);
2023-07-12 20:52:25 +03:00
final ThemeData baseDark = ThemeData.dark(useMaterial3: true);
2023-06-17 20:57:57 +03:00
2023-07-14 20:19:43 +03:00
const Color lightColor = Colors.white;
const Color darkColor = Color.fromRGBO(30, 30, 30, 1);
const Color oledColor = Colors.black;
2023-07-19 18:59:53 +03:00
ColorScheme colorSchemeLight = ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
);
2025-05-28 17:42:15 +03:00
2023-07-19 18:59:53 +03:00
ColorScheme colorSchemeDark = ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
);
2023-06-17 20:57:57 +03:00
2024-07-09 23:03:40 +03:00
ThemeData lightTheme(
2025-03-15 23:40:48 +03:00
Color? color,
ColorScheme? colorScheme,
bool edgeToEdgeAvailable,
) {
2025-05-28 17:42:15 +03:00
return _buildTheme(
baseTheme: baseLight,
2023-07-19 18:59:53 +03:00
brightness: Brightness.light,
2025-05-28 17:42:15 +03:00
color: color,
colorScheme: colorScheme,
edgeToEdgeAvailable: edgeToEdgeAvailable,
2023-07-19 18:59:53 +03:00
);
}
2023-06-17 20:57:57 +03:00
2024-07-09 23:03:40 +03:00
ThemeData darkTheme(
2025-03-15 23:40:48 +03:00
Color? color,
ColorScheme? colorScheme,
bool edgeToEdgeAvailable,
) {
2025-05-28 17:42:15 +03:00
return _buildTheme(
baseTheme: baseDark,
2023-07-19 18:59:53 +03:00
brightness: Brightness.dark,
2025-05-28 17:42:15 +03:00
color: color,
colorScheme: colorScheme,
edgeToEdgeAvailable: edgeToEdgeAvailable,
);
}
ThemeData _buildTheme({
required ThemeData baseTheme,
required Brightness brightness,
required Color? color,
required ColorScheme? colorScheme,
required bool edgeToEdgeAvailable,
}) {
final harmonizedColorScheme =
colorScheme
?.copyWith(
brightness: brightness,
surface: baseTheme.colorScheme.surface,
)
.harmonized();
return baseTheme.copyWith(
brightness: brightness,
colorScheme: harmonizedColorScheme,
textTheme: GoogleFonts.ubuntuTextTheme(baseTheme.textTheme),
appBarTheme: _buildAppBarTheme(
color,
baseTheme.colorScheme.onSurface,
edgeToEdgeAvailable,
brightness,
harmonizedColorScheme,
2023-07-19 18:59:53 +03:00
),
primaryColor: color,
canvasColor: color,
scaffoldBackgroundColor: color,
2025-05-28 17:42:15 +03:00
cardTheme: _buildCardTheme(color, harmonizedColorScheme),
bottomSheetTheme: _buildBottomSheetTheme(color, harmonizedColorScheme),
navigationRailTheme: baseTheme.navigationRailTheme.copyWith(
2023-07-19 18:59:53 +03:00
backgroundColor: color,
),
2025-05-28 17:42:15 +03:00
navigationBarTheme: _buildNavigationBarTheme(color, harmonizedColorScheme),
inputDecorationTheme: _buildInputDecorationTheme(),
);
}
AppBarTheme _buildAppBarTheme(
Color? color,
Color? onSurfaceColor,
bool edgeToEdgeAvailable,
Brightness brightness,
ColorScheme? colorScheme,
) {
return AppBarTheme(
backgroundColor: color,
foregroundColor: onSurfaceColor,
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
elevation: 0,
systemOverlayStyle: SystemUiOverlayStyle(
statusBarIconBrightness:
brightness == Brightness.light ? Brightness.dark : Brightness.light,
statusBarColor: Colors.transparent,
systemStatusBarContrastEnforced: false,
systemNavigationBarContrastEnforced: false,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarIconBrightness:
brightness == Brightness.light ? Brightness.dark : Brightness.light,
systemNavigationBarColor:
edgeToEdgeAvailable ? Colors.transparent : colorScheme?.surface,
2023-07-19 18:59:53 +03:00
),
);
2023-06-17 20:57:57 +03:00
}
2025-05-28 17:42:15 +03:00
CardThemeData _buildCardTheme(Color? color, ColorScheme? colorScheme) {
return CardThemeData(
color: color,
surfaceTintColor:
color == oledColor ? Colors.transparent : colorScheme?.surfaceTint,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
shadowColor: Colors.transparent,
);
}
BottomSheetThemeData _buildBottomSheetTheme(
Color? color,
ColorScheme? colorScheme,
) {
return BottomSheetThemeData(
backgroundColor: color,
surfaceTintColor:
color == oledColor ? Colors.transparent : colorScheme?.surfaceTint,
);
}
NavigationBarThemeData _buildNavigationBarTheme(
Color? color,
ColorScheme? colorScheme,
) {
return NavigationBarThemeData(
backgroundColor: color,
surfaceTintColor:
color == oledColor ? Colors.transparent : colorScheme?.surfaceTint,
);
}
InputDecorationTheme _buildInputDecorationTheme() {
return InputDecorationTheme(
labelStyle: WidgetStateTextStyle.resolveWith((Set<WidgetState> states) {
return const TextStyle(fontSize: 14);
}),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
);
}