The argument type 'Color?' can't be assigned to the parameter type 'MaterialColor?

7,797

Solution 1

If you want primarySwatch with Colors.yellow[700] as primaryColor you would have to create your own MaterialColor from color Colors.yellow[700] like this

final Map<int, Color> _yellow700Map = {
  50: Color(0xFFFFD7C2),
  100: Colors.yellow[100],
  200: Colors.yellow[200],
  300: Colors.yellow[300],
  400: Colors.yellow[400],
  500: Colors.yellow[500],
  600: Colors.yellow[600],
  700: Colors.yellow[800],
  800: Colors.yellow[900],
  900: Colors.yellow[700],
};

final MaterialColor _yellow700Swatch =
  MaterialColor(Colors.yellow[700].value, _yellow700Map);

and then add it as primarySwatch: _yellow700Swatch, or if you want only your background to be Colors.yellow[700] you can use canvasColor like this canvasColor: Colors.yellow[700],.

Solution 2

Also you can use colorScheme property and set like below :

theme: ThemeData(
    colorScheme: ColorScheme.fromSwatch().copyWith(

      primary: const Colors.yellow[700],
      secondary: const Colors.yellow.shade700,

      // or from RGB

      primary: const Color(0xFF343A40),
      secondary: const Color(0xFFFFC107),

    ),
  ),

Solution 3

primarySwatch only takes a ColorSwatch not a colorShade

if you want to use a shade you can try

    ThemeData(
        primaryColor: Colors.yellow[700]
    )

for more info primaryColor

Share:
7,797
Admin
Author by

Admin

Updated on December 22, 2022

Comments

  • Admin
    Admin over 1 year

    enter image description here

    I want to set the background Colors.yellow[700] in flutter,but when i add symbol "[]" or Colors.yellow.shade600, but i can't set the value for background. It shows error & the error is

    The argument type 'MaterialColor' can't be assigned to the parameter type 'Paint'