How to change the text color based on container background color?

1.4k Views Asked by At

I have a container that has a gradient background color with some text. I am showing the percentage at the end of the container. Depending upon the percentage, Green color should be applied from left to right. When the percentage hit 100%, The whole container will become green.

Now I want to know that how to achieve the text color becomes white where the container color changes to green and vice-versa.

Note : The text in the container and the percentage are from API.

I have attached image for reference below.

Image 1 Image 2

1

There are 1 best solutions below

3
On

in your case i think you can use something like this :

 Text(
                'text message',
                style: TextStyle(                   
                    color: ThemeData.estimateBrightnessForColor(_bgColor) ==
                            Brightness.light
                        ? Colors.green
                        : Colors.white),
              ),

for a complete guide try this documentation