Created
September 26, 2023 14:33
-
-
Save isaacadariku/f19874767ac6653d9c9ee9ace36cf41b to your computer and use it in GitHub Desktop.
Snippet of the color changes in reflection.app guide cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const double minLightness = 0.30; | |
const double maxLightness = 0.55; | |
const double lightnessRange = maxLightness - minLightness; | |
const int numberOfColors = 3; | |
/// The top card gradients logic | |
/// | |
/// Generate a list of gradient colors based on the provided [originalColor]. | |
/// This function generates three gradient colors by adjusting the lightness of the [originalColor]. | |
List<Color> generateGradientColors(Color originalColor) { | |
final hslColor = HSLColor.fromColor(originalColor); | |
final lightnessValues = generateRandomLightnessValues(numberOfColors); | |
final gradientColors = lightnessValues.map((lightness) { | |
final newHSLColor = hslColor.withLightness(lightness); | |
return newHSLColor.toColor(); | |
}).toList(); | |
return gradientColors; | |
} | |
List<double> generateRandomLightnessValues(int count) { | |
final random = Random(); | |
return List.generate( | |
count, | |
(index) => (random.nextDouble() * lightnessRange + minLightness).clamp(0.0, 1.0), | |
); | |
} | |
``` | |
/// The bottom color is gotten from this function | |
/// | |
/// Adjusts the lightness of the provided [color] based on the theme brightness of the [context]. | |
/// If the theme is dark, it decreases the lightness; otherwise, it increases the lightness. | |
Color adjustLightnessBasedOnTheme(Color color, BuildContext context) { | |
final hslColor = HSLColor.fromColor(color); | |
final isDarkTheme = context.isDark; | |
final adjustedLightness = isDarkTheme ? 0.1 : 0.95; | |
return hslColor.withLightness(adjustedLightness).toColor(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment