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'
To turn any color to material, You just follow below, Especially, when we try to give a primary swatch color, It only accepts the material color code. Now, Just create a variable for your custom color and specify your values in it for 50 to 900 for Luminance purpose. Map<int, Color> color ={50:Color.
A color that has a small table of related colors called a "swatch". The table is indexed by values of type T . See also: MaterialColor and MaterialAccentColor, which define material design primary and accent color swatches.
In the "Material You" framework there is a class named MaterialColor. This is not stated. All colors in Material classes are of type MaterialColor. The "Colors" class is a Material class that has public elements having the primary colors are names. Each of these elements is a List of type "MaterialColor".
It too has a class named Color. Because of type safety the two classes MaterialColor and Color are incompatible. Therefore whenever you want to create or reference a color in the Material frame work, use the type MaterialColor rather than the Dart type "Color" And be careful when you read a parameter named color or colors!
If you see Colors.blueAccent [100] actually gets a value from map. So if your version of flutter is bellow 2.0 you would get this error since it may return a null value.
Officially, black and white aren't even colors in the same way that a Tomato isn't officially a vegetable but a fruit. Weird, but true. so that's probably why black and white are treated differently in the Material design spec than the other "colors" that do have swatches.
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],
.
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),
),
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With