When you try to add a background color, you get an error message that says you can’t have a color and a box decoration. Anyone know how to fix this?
When you try to add a background color, you get an error message that says you can’t have a color and a box decoration. Anyone know how to fix this?
2
Answers
Because you don’t need to add color separately as decoration has the same property to achieve the same. Also it has the Border inside the same decoration prop using the
BoxDecoration
class.Check this thread Flutter BoxDecoration’s background color overrides the Container's background color, why?
The error message arises because you cannot directly specify both a color property and a decoration property with a color field in the same widget in Flutter. This is because both properties attempt to fill the background of the widget, leading to ambiguity and potential inconsistencies.
Here’s how to fix the issue:
Use decoration with color:
If you want to use a solid color background, utilize the BoxDecoration widget within the decoration property: