How to give color shade in BoxDecoration
?
Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
//color: Color(0x64A3D7FF), // <== this is working fine
color: Colors.blue[100], // <= Why this is giving me "Invalid constant value."
),
alignment: Alignment.center,
width: 210,
height: 100,
)
CodePudding user response:
You are using const
before BoxDecoration
and using Colors.blue[100]
means reading map and which is not compile time constant. It will get data on runtime.
You can explore the color,
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),
},
);
Therefore, you can not use const
with color[value]
Container(
decoration: BoxDecoration( // remove const
borderRadius: BorderRadius.all(Radius.circular(10)),
color: Colors.blue[100],
),
CodePudding user response:
Just Remove the const
keyword used before the boxdecoration, and it will work correctly