Skip to content

Instantly share code, notes, and snippets.

@danReynolds
Created January 29, 2024 16:36
Show Gist options
  • Save danReynolds/3229c856fc11766c75097d0c86a86346 to your computer and use it in GitHub Desktop.
Save danReynolds/3229c856fc11766c75097d0c86a86346 to your computer and use it in GitHub Desktop.
Brighten extension
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