1

I want a colour for container but getting error while using colour.

My code:

Container(
    color:Colors.red,
    width: 50,
    height: 50,
    decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(50)
    )
),
VincentDR
  • 696
  • 3
  • 15
Umesh Rajput
  • 218
  • 1
  • 11
  • Does this answer your question? [Flutter BoxDecoration’s background color overrides the Container's background color, why?](https://stackoverflow.com/questions/45724567/flutter-boxdecoration-s-background-color-overrides-the-containers-background-co) – Sagar Acharya Nov 16 '22 at 10:29

6 Answers6

3

You cannot add color to the container if you add decorations. The solution is to enter color into the decoration box as follows

Container( 
  width: 50, 
  height: 50, 
  decoration: BoxDecoration(color: Color.red)
)
ariga
  • 76
  • 3
2

You can't use "color" and "decoration" at the same time. You need to pass the "color" parameter to the "BoxDecoration" widget like this:

Container(
    width: 50,
    height: 50,
    decoration: BoxDecoration(
         color:Colors.red,
         borderRadius: BorderRadius.circular(50)
    )
),
VincentDR
  • 696
  • 3
  • 15
1

Use color inside container directly to set the background for the children. If you use any decoration then it will conflict with outside color. In those case you need to give color inside decoration.

FullCode : here

Column(
  children: [
    Container(
      padding: EdgeInsets.all(10),
      color: Colors.green,
      child: Text('test'),
    ),
    SizedBox(height: 10),
    Container(
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.green,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Text('test'),
    )
  ],
)

Output for the above code is

enter image description here

Vignesh KM
  • 1,979
  • 1
  • 18
  • 24
0

Please use color in BoxDecoration like this

Container( width: 50, height: 50, decoration: BoxDecoration( borderRadius: BorderRadius.circular(50),color:Colors.red,)),

Umesh Rajput
  • 218
  • 1
  • 11
0

You can't give both colors and decoration to Container(). If you are looking to give color and decoration to Container, give color inside Boxdecoration

Container( width: 50, height: 50, decoration: BoxDecoration(color: Color.red) )

0

The container does not accept the color parameter when there is a decoration parameter. This happens because the BoxDecoration has a color parameter. Just put the color inside the BoxDecoration and remove the color parameter from the Container and your problem will be solved.

Container(
    width: 50,
    height: 50,
    decoration: BoxDecoration(
         borderRadius: BorderRadius.circular(50),
         color: Colors.red
    )
),