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'

Upvotes: 3

Views: 1728

Answers (2)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63604

shade100 is a getter for MaterialColor. You can do

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

Upvotes: 2

Wiktor
Wiktor

Reputation: 775

You can't change the shade of the color again in the widget tree. Though you've got plenty of other methods to manipulate the color with. For example, objeColor.withAlpha(75) looks exactly like Colors.orange.shade100 so it would perfectly fit your needs. In other usecases you can try to experiment with other methods, like withOpacity().

Upvotes: 0

Related Questions