Alexandra Damaschin
Alexandra Damaschin

Reputation: 840

Reuse custom color in ThemeData

I have a class for declaring custom colors.

class CustomColors {
static const Color myCustomBlack = const Color(0x8A000000);
}

My question is: Why I can not use them in Theme data as follows?

ThemeData(primarySwatch : CustomColors.myCustomBlack)

Upvotes: 0

Views: 268

Answers (1)

CopsOnRoad
CopsOnRoad

Reputation: 267444

primarySwatch isn't a normal Color, it is a MaterialColor, so you can't assign any Color to it. And a MaterialColor is the one which has shades like 100, 200, ... 900.

For example:

Colors.blue is a MaterialColor as you can use shades like Colors.blue[100] and Colors.black isn't a MaterialColor, you get error on using Colors.black[100].

Upvotes: 1

Related Questions