Created
January 29, 2024 16:36
-
-
Save danReynolds/3229c856fc11766c75097d0c86a86346 to your computer and use it in GitHub Desktop.
Brighten extension
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
extension ColorExtensions on Color { | |
String toHex() => | |
'#${(value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'; | |
bool get isDark { | |
return ThemeData.estimateBrightnessForColor(this) == Brightness.dark; | |
} | |
Color darken([int percent = 10]) { | |
assert(1 <= percent && percent <= 100); | |
var f = 1 - percent / 100; | |
return Color.fromARGB( | |
alpha, (red * f).round(), (green * f).round(), (blue * f).round()); | |
} | |
Color brighten([int percent = 10]) { | |
assert(1 <= percent && percent <= 100); | |
var p = percent / 100; | |
return Color.fromARGB(alpha, red + ((255 - red) * p).round(), | |
green + ((255 - green) * p).round(), blue + ((255 - blue) * p).round()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment