Detect color is light or dark in flutter

548

To check whether color is dark or light, we will need to convert that color into its greyscale color. Formula to find grayscale of any color from its RGB value is:

grayscale = (0.299 * Red) + (0.587 * Green) + (0.114 * Blue)

And than check:

if(grayscale > 128){
    // color is light
}else{
    // color is dark
}
Share:
548
Noobdeveloper
Author by

Noobdeveloper

Updated on December 30, 2022

Comments

  • Noobdeveloper
    Noobdeveloper over 1 year

    Is there any way to check color is dark or ligh , in the sense black tone or white in flutter and get a boolean value true or false