Reputation: 55
I was working with Colors class in Flutter. Added a buildkey function with input "Color zinc" and the same takes the value like Colors.red, Colors purple etc.
However, if I add the input as "Colors Zinc" the values like Colors.red, Colors.purple throws an error. Why this is so?
The class Colors should match the input class (Colors in this case) I think?enter image description here
Upvotes: 0
Views: 905
Reputation: 55
May be I found the solution of my issue..
When i looked into the dart file of colors class. I found that, Colors.green is actually an object of Color class. Code is something like this
Class Colors
Color green = Color(....);
Might be that is the reason thats why it requires it requires color class while initilization of variable and not Colors.
Upvotes: 0
Reputation: 730
It would be helpful if you could attach a screenshot or maybe paste the exact error that you are getting.
But meanwhile as I understood it, It seems like that you are telling this works fine for you:
Expanded buildkey(Color zinc, int buildnumber) { ... }
But you are getting some error with this:
Expanded buildkey(Colors zinc, int buildnumber) { ... }
Which is correct behaviour as Colors.[color] returns a swatch constant which is of type color.
e.g: Color selection = Colors.green[400];
For more info: https://api.flutter.dev/flutter/material/Colors-class.html
Upvotes: 1