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, ) ), ) ) )
To set border radius for Container widget, set its decoration property with BoxDecoration where the borderRadius property is set with required value.
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.
Simply wrap your widget with ClipRRect and give a radius. You can specify which corner you want to make round.
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"), ], ), ), ), )
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With