flutteruser-interfacecolors

Detect color is light or dark in flutter


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


Solution

  • 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
    }