Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

border radius not apply inside container widget

Tags:

flutter

Border radius not apply inside child Container. Tried with SizedBox & Stack widget. I need border view inside container.

Scaffold(   appBar: AppBar(     title: new Text("ListView"),   ),   body: Center(       child: Padding(         padding: EdgeInsets.all(15.0),         child: Container(             decoration: BoxDecoration(                 borderRadius: BorderRadius.circular(15.0),                 border: Border.all(                     color: Colors.green,                     width: 2.0                 )             ),             child: Container(               color: Colors.red,             )         ),       )   ) ) 

like image 412
NIRAV PATEL Avatar asked Sep 03 '18 10:09

NIRAV PATEL


People also ask

How do you set the border radius of a container?

To set border radius for Container widget, set its decoration property with BoxDecoration where the borderRadius property is set with required value.

Why border radius is not working?

If there are contents within the div that has the curved corners, you have to set overflow: hidden because otherwise the child div's overflow can give the impression that the border-radius isn't working. This answer worked for me.

How do you apply the border radius to only one side in Flutter?

Simply wrap your widget with ClipRRect and give a radius. You can specify which corner you want to make round.


2 Answers

Try this, Use ClipRRect and nest inside another Container and now you can add non-uniform borders

Container(                     decoration: BoxDecoration(                       color: Colors.white,                       borderRadius: BorderRadius.circular(10),                       boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 5)],                     ),                     child: ClipRRect(                       borderRadius: BorderRadius.circular(10),                       child: Container(                         padding: EdgeInsets.all(20),                         decoration: BoxDecoration(                           border: Border(                             left: BorderSide(color: Colors.indigo, width: 5),                           ),                         ),                         child: Column(                           mainAxisSize: MainAxisSize.min,                           children: <Widget>[                             Icon(Icons.home),                             Text("Home"),                           ],                         ),                       ),                     ),                   ) 
like image 115
Raj Yadav Avatar answered Oct 08 '22 01:10

Raj Yadav


decoration is painted behind the child. If you want the decoration to be applied in front of the container's child, use foregroundDecoration

Scaffold(   appBar: AppBar(     title: new Text("ListView"),   ),   body: Center(       child: Padding(         padding: EdgeInsets.all(15.0),         child: Container(             foregroundDecoration: BoxDecoration(                 borderRadius: BorderRadius.circular(15.0),                 border: Border.all(                     color: Colors.green,                     width: 2.0                 )             ),             child: Container(               color: Colors.red,             )         ),       )   ) ) 

above code paints border in front of the child container. Please note that, even with foregroundDecoration child container would still have sharp corners.

If you want child container to have rounded corners, either you need apply borderRadius to child container or use ClipRRect with same border radius as parent container

like image 37
Hari Prasad Avatar answered Oct 07 '22 23:10

Hari Prasad