Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter give container rounded border

Tags:

flutter

dart

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?

like image 837
Karel Debedts Avatar asked Sep 03 '19 19:09

Karel Debedts


People also ask

How do you give rounded border to container flutter?

In flutter, it is simple to create an easy rectangle and sq. form using container widget however they need sharp edges and therefore the corner is sharp however using the BoxDecoration property of box decoration we are able to simply and make the perimeters rounded. Container( decoration: BoxDecoration( border: Border.

How to round the corners of a box in flutter?

In flutter, it is simple to create an easy rectangle and sq. form using container widget however they need sharp edges and therefore the corner is sharp however using the BoxDecoration property of box decoration we are able to simply and make the perimeters rounded.

How to show a widget with rounded borders in flutter?

Want to show a widget with rounded borders in Flutter? Just wrap your widget with a DecoratedBox and give it a decoration like this: DecoratedBox( decoration: BoxDecoration( color: Colors.blue, borderRadius: const BorderRadius.all(Radius.circular(16)), // alternatively, do this: // borderRadius: BorderRadius.circular (16), ) child: someWidget, )

Why does my container have a rounded Shadow?

Edit: The rounded shadow you are getting is because of the offset that you have used for the inner container. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

What are the best resources to learn flutter?

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.


3 Answers

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: ...
)
like image 167
Evaldo Bratti Avatar answered Oct 14 '22 06:10

Evaldo Bratti


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: ...
    )
like image 43
S.R Keshav Avatar answered Oct 14 '22 06:10

S.R Keshav


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'),
),
like image 22
NavodDinidu Avatar answered Oct 14 '22 08:10

NavodDinidu