Home > Blockchain >  primarySwatch isn't setting primaryColor
primarySwatch isn't setting primaryColor

Time:08-13

I have read that primaryColor is a Color, primarySwatch is MaterialColor, which includes various set of a Color.

first, according to my flutter class, I set Theme like this

primarySwatch: Colors.pink,
        accentColor: Colors.amber,

and when I set splashColor of InkWell, it worked.

splashColor: Theme.of(context).primaryColor,

but the VsCode suggest me a better way, and automatically migrated Theme like this

colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.pink)
               .copyWith(secondary: Colors.amber),

But the new way does not changes primaryColor of splashColor, I checked it Through By print the Color, but the Color was 0xff2196f3, which is default I think(close to blue).

so Why the new way does not set primaryColor?

CodePudding user response:

in new way, you should use it like this:

splashColor: Theme.of(context).colorScheme.primary,
  • Related