RoundedRectangleBorder is not working for Container widget
Asked Answered
C

3

8

I need to make Container edge circle and how to do that when i try RoundedRectangleBorder it showing error

 Container(
      width: 100,height: 100,
      margin: EdgeInsets.all(10.0),
      decoration: BoxDecoration(
         color: Colors.orange,
         shape: RoundedRectangleBorder(
            borderRadius: new BorderRadius.circular(18.0),
         )
      ),
 ),
Contemporize answered 21/12, 2019 at 11:3 Comment(0)
J
7

This error suggests,

argument type RoundedRectangleBorder cannot be assigned to parameter type BoxShape

So if you want to use RoundedRectangleBorder then you have to use it inside shape parameter,

Container(
            width: 100,height: 100,
            margin: EdgeInsets.all(10.0),
                    decoration:  ShapeDecoration(
                color: Colors.orange,
              shape: RoundedRectangleBorder( // <--- use this
                borderRadius: BorderRadius.all(
                  Radius.circular(10),
                ),
              ),
            ),
       ),

Output,

enter image description here

@Anil Chauhan's approach is also correct so you can use that too.

Jermyn answered 21/12, 2019 at 12:52 Comment(0)
M
2

Try this:

 Container(
     width: 100,height: 100,
     margin: EdgeInsets.all(10.0),
     decoration: BoxDecoration(
       color: Colors.orange,
       borderRadius: BorderRadius.circular(10.0)
    ),
 ),
Matriculation answered 21/12, 2019 at 11:12 Comment(0)
T
0

The container is no longer accepting RoundedRectangledBorder as a shape, You've to use the BoxShape class only for the shape property

But still, you can achieve the desired behavior like this

Container(decoration: BoxDecoration(border: Border.all(color: Colors.purple, width:2),color:Colors.purple.withOpacity(0.2),shape:BoxShape.rectangle,borderRadius: BorderRadius.circular(12.0)),

By doing this you can give borderRadius,shape and borders as well

if you're not getting the borderRadius the you can wrap your container inside a ClipRRect() and access the borderRadius property inside the ClipRRect

Tersanctus answered 30/11, 2023 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.