Search code examples
flutterdartcolors

apply shade to flutter color variable


I have defined a variable that holds a color value and when I setstate the screen, I always change this color. I want to use this color both as normal and shade100 in my application. However, my code is giving an error below.

late Color objeColor;
objeColor = Colors.orange;

Container(
   decoration: BoxDecoration(
   shape: BoxShape.circle,
   color: objeColor, // there is no error *******
   ),),


Container(
   decoration: BoxDecoration(
   shape: BoxShape.circle,
   color: objeColor.shade100, // there is error *******
),),

error

The getter 'shade100' isn't defined for the type 'Color'. Try importing the library that defines 'shade100', correcting the name to the name of an existing getter, or defining a getter or field named 'shade100'


Solution

  • shade100 is a getter for MaterialColor. You can do

     late MaterialColor objeColor;
     ...
     color: objeColor.shade100