Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

String is not a subtype of Color

I have a picture on the page and below it a color pallette of 9 colors. When user clicks a color from the pallette, the image is to show that color on it. For that I want to use an array and I am changing a variable on tap

selectedIndex = 0  ->  8;

And I want to pass the color in ColorFilter

 child: ColorFiltered(
                colorFilter: ColorFilter.mode(
                    Color(filters[selectedIndex]),
                    BlendMode.color),
                child: Image('')),

I am getting an error. String is not subtype of Color. How can I do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is my filters array

   "Colors.black",
   "Colors.blue",
   "Colors.yellow",
   "Colors.orange",
   "Colors.pink",
   "Colors.green",
   "Colors.white",
   "Colors.indigo",
   "Colors.grey",
   "Colors.red",
 ];

>Solution :

It expects a Color type, not a String. Remove the quotes

[
Colors.black,
Colors.blue,
Colors.yellow,
etc..
];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading