flutter_statusbarcolor
flutter_statusbarcolor copied to clipboard
useWhiteForeground() should use "HSP Color Model" for better results
http://alienryderflex.com/hsp.html
Current implementation tends to choose black in cases when white is much more appropriate.
/// Returns - a number in the rage of 0 (black) to 255 (white).
///
/// See **HSP Color Model**: http://alienryderflex.com/hsp.html
static int calcBrightness(Color color) {
var v = sqrt(pow(color.red, 2) * 0.299 + pow(color.green, 2) * 0.587 + pow(color.blue, 2) * 0.114);
int brightness = v.round();
return brightness;
}
static bool useWhiteForeground(Color color) {
// I selected cutoff value of 130 by trial and error and it reflects my taste,
// every value in the rage 128-145 will give acceptable results.
return calcBrightness(color) < 130 ? true : false;
}