266

I'm making a Container(), I gave it a border, but it would be nice to have rounded borders.

This is what I have now:

Container(
      width: screenWidth / 7,
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.red[500],
        ),
      ),
      child: Padding(
        padding: EdgeInsets.all(5.0),
        child: Column(
          children: <Widget>[
            Text(
              '6',
              style: TextStyle(
                  color: Colors.red[500],
                  fontSize: 25),
            ),
            Text(
             'sep',
              style: TextStyle(
                  color: Colors.red[500]),
            )
          ],
        ),
      ),
    );

I tried putting ClipRRect on it, but that crops the border away. Is there a solution for this?

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
Karel Debedts
  • 5,226
  • 9
  • 30
  • 70

14 Answers14

522

Try using the property borderRadius from BoxDecoration

Something like

Container(
  decoration: BoxDecoration(
    border: Border.all(
      color: Colors.red[500],
    ),
    borderRadius: BorderRadius.all(Radius.circular(20))
  ),
  child: ...
)
Evaldo Bratti
  • 7,078
  • 2
  • 18
  • 19
  • 72
    `BorderRadius.circular(20)` can be used as shorthand for `BorderRadius.all(Radius.circular(20))` – Exfridos Mar 26 '21 at 14:23
103

To make it completely circle:

Container(
      decoration: BoxDecoration(
        shape: BoxShape.circle,
      ),
    )

To make it a circle at selected spots:

Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
            topRight: Radius.circular(40.0),
            bottomRight: Radius.circular(40.0),
            topLeft: Radius.circular(40.0),
            bottomLeft: Radius.circular(40.0)),
      ),
      child: Text("hello"),
    ),

or

  Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(20)),
      ),
      child: ...
    )
Hamaad
  • 88
  • 8
S.R Keshav
  • 1,965
  • 1
  • 11
  • 14
31

It can be done in several ways.

  • If you have a simple rounded corner to implement use ClipRRect, ClipOval
  • If you want to have more command over the rounded corneres use BoxDecoration inside the Container

ClipRRect

enter image description here

 ClipRRect(
    borderRadius: BorderRadius.circular(20),
    child: Container(height: 100, width: 100, color: Colors.orange)),

ClipOval

enter image description here

ClipOval(
    child: Container(height: 100, width: 100, color: Colors.orange)),

BoxDecoration

  • Border across all the corners

enter image description here

 Container(
   decoration: BoxDecoration(
   borderRadius: BorderRadius.circular(10),
   color: Colors.orange),
   height: 100,
   width: 100,
 );
  • Border in a particular corner

enter image description here

 Container(
    decoration: const BoxDecoration(
      borderRadius: BorderRadius.only(
       topLeft: Radius.circular(40),
       bottomRight: Radius.circular(40)),
      color: Colors.orange),
    height: 100,
    width: 100,
 ),
  • Border in a particular axis

enter image description here

  Container(
    decoration: const BoxDecoration(
      borderRadius: BorderRadius.horizontal(
        right: Radius.circular(60),
        ),
      color: Colors.orange),
    height: 100,
    width: 100,
  );
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
20

You can use like this. If you want border for all the corners you can use like bellow.

Container(
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(
      Radius.circular(12.0),
    ),
  ),
),

If you want rounded borders for selected sides only you can use like below.

Container(
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(10),
      topRight: Radius.circular(10),
    ),
  ),
  child: Text('Text'),
),
Alp Altunel
  • 3,324
  • 1
  • 26
  • 27
NavodDinidu
  • 383
  • 3
  • 6
13

You can use ClipRRect Widget:

ClipRRect (
  borderRadius: BorderRadius.circular(5.0),
  child: Container(
                    height: 25,
                    width: 40,
                    color: const Color(0xffF8742C),
                    child: Align(
                        alignment: Alignment.center,
                        child: Text("Withdraw"))),
          )
MendelG
  • 14,885
  • 4
  • 25
  • 52
Adam Shelby
  • 141
  • 1
  • 3
10

Enhancement for the above answer.

Container(
  decoration: BoxDecoration(
    border: Border.all(
      color: Colors.red[500],
    ),
   borderRadius: BorderRadius.circular(20) // use instead of BorderRadius.all(Radius.circular(20))
  ),
  child: ...
)
hsul4n
  • 491
  • 7
  • 15
  • 7
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 10 '20 at 06:22
  • 1
    Sorry, I miss that. – hsul4n Aug 11 '20 at 09:47
6

To make a complete circle just use shape property :

Container(
   padding: const EdgeInsets.all(4),
   decoration: BoxDecoration(
     shape: BoxShape.circle,
     color: Colors.black,
   ),                            
   child: Icon(
      Icons.add,
      size: 15.0,
      color: Colors.white,
     ),
                               
                                

Here is picture

Hanisha
  • 849
  • 10
  • 8
4
Container(
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(20.0),
      border: Border.all(
        color: HexColor('#C88A3D'),
        width: 3.0
      )
    ),
    child: Container(
      decoration: new BoxDecoration(borderRadius:
      BorderRadius.circular(20.0),
      color: Colors.white,),
    )
  ),
SoftDev365
  • 71
  • 3
2

The key here is to add a BorderRadius:

Container(    
  decoration: BoxDecoration(
    border: Border.all(
      color: Colors.red[340],
     ),
     borderRadius: BorderRadius.all(Radius.circular(35),
   ),
   child: `enter code here`
),
powerj1984
  • 2,216
  • 1
  • 22
  • 34
Rohit Sharma
  • 71
  • 1
  • 4
  • 2
    While this code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn and eventually apply that knowledge to their own code. You are also likely to have positive-feedback/upvotes from users, when the code is explained. – Amit Verma Feb 10 '21 at 12:04
2

just with put this at the Container

Container(
  decoration: BoxDecoration(
    borderRadius: BorderRadius.all(Radius.circular(30))
  ),
)
Mohamed Reda
  • 1,207
  • 13
  • 21
1

Just simply use circle shape shape: BoxShape.circle in BoxDecoration. All code be like

Container(
  decoration: BoxDecoration(
    shape: BoxShape.circle
  ),
)
Dinith
  • 839
  • 14
  • 22
0

Just to show another way to do the same thing.

Might be useful when needs to use InkWell around Container.

Material(
 shape: RoundedRectangleBorder(
   borderRadius: BorderRadius.circular(8),
 ),
 child: Container(
   height: 100,
   width: 150,
 ),
);
Coala Jedi
  • 399
  • 3
  • 9
0
SizedBox(
                            child: (Container(
                              decoration: BoxDecoration(
                                  color: Colors.grey,
                                  border: Border.all(
                                    color: Colors.grey,
                                  ),
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(20))),
                              child: Column(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceAround,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      Text('00'),

                                      Padding(
                                        padding: const EdgeInsets.fromLTRB(
                                            2.0, 0, 0, 0),
                                        child: Container(
                                          padding: const EdgeInsets.all(8),
                                          decoration: BoxDecoration(
                                            shape: BoxShape.circle,
                                            color: Colors.white,
                                          ),
                                          child: CustomText(
                                            "2",
                                            color: Colors.black,
                                          ),
                                        ),
                                      ), // text
                                    ],
                                  ),
                                ],
                              ),
                            )),
                            width: 60,
                          ),
btm me
  • 368
  • 3
  • 11
0

use decoration property to give radius in Container

 decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
            topRight: Radius.circular(15),
            bottomLeft: Radius.circular(15)),
      ),

or 

Container(
  decoration: BoxDecoration(
    color: Colors.red,
    borderRadius: BorderRadius.all(
      Radius.circular(12.0),

    ),
  ),
),
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '23 at 11:39