Flutter: Why Colors.blue is a const value but Colors.blue.shade50 is not?
While giving color values to a couple of circleavatars I realized that flutter gives error to the color shades but not to the colors?
children: [
๐คข const CircleAvatar(backgroundColor: Colors.blue.shade50,),
๐ const CircleAvatar(backgroundColor: Colors.yellow,),
๐ CircleAvatar(backgroundColor: Colors.blueGrey.shade100,),
๐ const CircleAvatar(backgroundColor: Colors.grey,),
],
const CircleAvatar(backgroundColor: Colors.blue.shade50,) gives error invalid constant error.
I found that Colors.blue.shade50 interprets as Colors.blue[50].
Operator [] returns list. Hence, do not meet the definition of const.
The other alternative is to use the actual color value.
As per the screenshot Colors.blue.shade50 = Colors.blue[50] = Color(0xFFE3F2FD).
So if we use const CircleAvatar(backgroundColor: Color(0xFFE3F2FD)), this will be a valid solution.
ย