Search code examples
flutterlayoutcolorsthemes

How can I set primaryContainer color with ColorScheme.fromSwatch() in Material Theme


colorScheme offers in general the primaryContainer parameter. However, when I use `colorScheme.fromSwatch' this is no longer available such as many other parameters.

My understanding of fromSwatch is, I create a standard theme based on the key colors that I define within the color.Scheme. At least this is what I am aiming to do.

So how can I adapt the primaryContainer without defining every mandatory parameter of a scheme?


Solution

  • You can use copyWith method.

    ColorScheme.fromSwatch().copyWith(
        primaryContainer: Colors.red,
      ),
    

    More about ColorScheme