skip to Main Content

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


  1. 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?

    Login or Signup to reply.
  2. 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:

    1. Use decoration with color:

      If you want to use a solid color background, utilize the BoxDecoration widget within the decoration property:

    Container(
      decoration: BoxDecoration(
        color: Colors.blue,  // Set the desired background color
      ),
    
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search