Skip to content

Commit

Permalink
feat: Inject all colors from palette in an extension (#5267)
Browse files Browse the repository at this point in the history
* Provide V2 colors in an extension

* Fix copyWith method
  • Loading branch information
g123k authored May 18, 2024
1 parent d2d8d0a commit f9797bc
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/themes/smooth_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -40,6 +41,9 @@ class SmoothTheme {
return ThemeData(
useMaterial3: false,
primaryColor: DARK_BROWN_COLOR,
extensions: <SmoothColorsThemeExtension>[
SmoothColorsThemeExtension.defaultValues(),
],
colorScheme: myColorScheme,
canvasColor: themeProvider.currentTheme == THEME_AMOLED
? myColorScheme.background
Expand Down
160 changes: 160 additions & 0 deletions packages/smooth_app/lib/themes/smooth_theme_colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import 'package:flutter/material.dart';

class SmoothColorsThemeExtension
extends ThemeExtension<SmoothColorsThemeExtension> {
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<SmoothColorsThemeExtension> 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<SmoothColorsThemeExtension> lerp(
covariant ThemeExtension<SmoothColorsThemeExtension>? 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,
)!,
);
}
}

0 comments on commit f9797bc

Please sign in to comment.