Error while changing the flutter theme color to black

Also you cold simply use

theme: ThemeData.dark()

to change your applications theme to Dark


You can't use Colors.black because it is not a MaterialColor and primarySwatch expects a material color palette.

If you go to the definition of ThemeData you will see the following:

  ///  * The primary color palette (the [primarySwatch]), chosen from
  ///    one of the swatches defined by the material design spec. This
  ///    should be one of the maps from the [Colors] class that do not
  ///    have "accent" in their name.

For instance, the definition of Colors.blue is:

  static const MaterialColor blue = MaterialColor(
    _bluePrimaryValue,
    <int, Color>{
       50: Color(0xFFE3F2FD),
      100: Color(0xFFBBDEFB),
      200: Color(0xFF90CAF9),
      300: Color(0xFF64B5F6),
      400: Color(0xFF42A5F5),
      500: Color(_bluePrimaryValue),
      600: Color(0xFF1E88E5),
      700: Color(0xFF1976D2),
      800: Color(0xFF1565C0),
      900: Color(0xFF0D47A1),
    },
  );
  static const int _bluePrimaryValue = 0xFF2196F3;

While the definition of Colors.black is:

static const Color black = Color(0xFF000000);

That is why you can't use black there. For the same reason you can't use Colors.white. Those two are the exceptions to the above explanation of using colors that doesn't have the accent word.

If you want black, you can create your own palette:

const MaterialColor primaryBlack = MaterialColor(
  _blackPrimaryValue,
  <int, Color>{
    50: Color(0xFF000000),
    100: Color(0xFF000000),
    200: Color(0xFF000000),
    300: Color(0xFF000000),
    400: Color(0xFF000000),
    500: Color(_blackPrimaryValue),
    600: Color(0xFF000000),
    700: Color(0xFF000000),
    800: Color(0xFF000000),
    900: Color(0xFF000000),
  },
);
const int _blackPrimaryValue = 0xFF000000;

And then use the primaryBlack instead of Colors.black.

You could adjust the different colors in the palette.