Flutter BoxDecoration’s background color overrides the Container's background color, why?

Issue

I have a Flutter Container widget and I defined a color for it (pink), but for some reason, the color in BoxDecoration overrides it (green). Why?

new Container(
  color: Colors.pink,
  decoration: new BoxDecoration(
    borderRadius: new BorderRadius.circular(16.0),
    color: Colors.green,
  ),
);

Solution

Container’s color is shorthand for BoxDecoration’s color, so BoxDecoration’s color in the Container’s decoration property overrides its Container’s color.

Answered By – Mary

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *