From f9797bc8325f9300954cf0cbfb9f7d6aed8c4cac Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Sat, 18 May 2024 15:03:30 +0200 Subject: [PATCH] feat: Inject all colors from palette in an extension (#5267) * Provide V2 colors in an extension * Fix copyWith method --- .../smooth_app/lib/themes/smooth_theme.dart | 4 + .../lib/themes/smooth_theme_colors.dart | 160 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 packages/smooth_app/lib/themes/smooth_theme_colors.dart diff --git a/packages/smooth_app/lib/themes/smooth_theme.dart b/packages/smooth_app/lib/themes/smooth_theme.dart index 37017aef0a2..417fbfdab2e 100644 --- a/packages/smooth_app/lib/themes/smooth_theme.dart +++ b/packages/smooth_app/lib/themes/smooth_theme.dart @@ -4,6 +4,7 @@ import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/themes/color_provider.dart'; import 'package:smooth_app/themes/color_schemes.dart'; import 'package:smooth_app/themes/contrast_provider.dart'; +import 'package:smooth_app/themes/smooth_theme_colors.dart'; import 'package:smooth_app/themes/theme_provider.dart'; class SmoothTheme { @@ -40,6 +41,9 @@ class SmoothTheme { return ThemeData( useMaterial3: false, primaryColor: DARK_BROWN_COLOR, + extensions: [ + SmoothColorsThemeExtension.defaultValues(), + ], colorScheme: myColorScheme, canvasColor: themeProvider.currentTheme == THEME_AMOLED ? myColorScheme.background diff --git a/packages/smooth_app/lib/themes/smooth_theme_colors.dart b/packages/smooth_app/lib/themes/smooth_theme_colors.dart new file mode 100644 index 00000000000..0d5700760df --- /dev/null +++ b/packages/smooth_app/lib/themes/smooth_theme_colors.dart @@ -0,0 +1,160 @@ +import 'package:flutter/material.dart'; + +class SmoothColorsThemeExtension + extends ThemeExtension { + SmoothColorsThemeExtension({ + required this.primaryBlack, + required this.primaryDark, + required this.primarySemiDark, + required this.primaryNormal, + required this.primaryMedium, + required this.primaryLight, + required this.secondaryNormal, + required this.secondaryLight, + required this.green, + required this.orange, + required this.red, + required this.grayDark, + required this.grayLight, + }); + + SmoothColorsThemeExtension.defaultValues() + : primaryBlack = const Color(0xFF341100), + primaryDark = const Color(0xFF483527), + primarySemiDark = const Color(0xFF52443D), + primaryNormal = const Color(0xFFA08D84), + primaryMedium = const Color(0xFFEDE0DB), + primaryLight = const Color(0xFFF6F3F0), + secondaryNormal = const Color(0xFFF2994A), + secondaryLight = const Color(0xFFEE8858), + green = const Color(0xFF219653), + orange = const Color(0xFFFB8229), + red = const Color(0xFFEB5757), + grayDark = const Color(0xFF666666), + grayLight = const Color(0xFF8F8F8F); + + final Color primaryBlack; + final Color primaryDark; + final Color primarySemiDark; + final Color primaryNormal; + final Color primaryMedium; + final Color primaryLight; + final Color secondaryNormal; + final Color secondaryLight; + final Color green; + final Color orange; + final Color red; + final Color grayDark; + final Color grayLight; + + @override + ThemeExtension copyWith({ + Color? primaryBlack, + Color? primaryDark, + Color? primarySemiDark, + Color? primaryNormal, + Color? primaryMedium, + Color? primaryLight, + Color? secondaryNormal, + Color? secondaryLight, + Color? green, + Color? orange, + Color? red, + Color? grayDark, + Color? grayLight, + }) { + return SmoothColorsThemeExtension( + primaryBlack: primaryBlack ?? this.primaryBlack, + primaryDark: primaryDark ?? this.primaryDark, + primarySemiDark: primarySemiDark ?? this.primarySemiDark, + primaryNormal: primaryNormal ?? this.primaryNormal, + primaryMedium: primaryMedium ?? this.primaryMedium, + primaryLight: primaryLight ?? this.primaryLight, + secondaryNormal: secondaryNormal ?? this.secondaryNormal, + secondaryLight: secondaryLight ?? this.secondaryLight, + green: green ?? this.green, + orange: orange ?? this.orange, + red: red ?? this.red, + grayDark: grayDark ?? this.grayDark, + grayLight: grayLight ?? this.grayLight, + ); + } + + @override + ThemeExtension lerp( + covariant ThemeExtension? other, + double t, + ) { + if (other is! SmoothColorsThemeExtension) { + return this; + } + + return SmoothColorsThemeExtension( + primaryBlack: Color.lerp( + primaryBlack, + other.primaryBlack, + t, + )!, + primaryDark: Color.lerp( + primaryDark, + other.primaryDark, + t, + )!, + primarySemiDark: Color.lerp( + primarySemiDark, + other.primarySemiDark, + t, + )!, + primaryNormal: Color.lerp( + primaryNormal, + other.primaryNormal, + t, + )!, + primaryMedium: Color.lerp( + primaryMedium, + other.primaryMedium, + t, + )!, + primaryLight: Color.lerp( + primaryLight, + other.primaryLight, + t, + )!, + secondaryNormal: Color.lerp( + secondaryNormal, + other.secondaryNormal, + t, + )!, + secondaryLight: Color.lerp( + secondaryLight, + other.secondaryLight, + t, + )!, + green: Color.lerp( + green, + other.green, + t, + )!, + orange: Color.lerp( + orange, + other.orange, + t, + )!, + red: Color.lerp( + red, + other.red, + t, + )!, + grayDark: Color.lerp( + grayDark, + other.grayDark, + t, + )!, + grayLight: Color.lerp( + grayLight, + other.grayLight, + t, + )!, + ); + } +}