Need rounded corner only for edges of inner grids. In the below image, rounded corner only for
BBC News -> (top+bottom) right
ABC News -> (top+bottom) left
If there are more than two columns, then second columns items should have rounded edges on both left and right
child: Container(
alignment: Alignment.bottomCenter,
padding: EdgeInsets.fromLTRB(10, 0, 10, 10),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topRight: const Radius.circular(8.0),
bottomRight: const Radius.circular(8.0),
),
image: DecorationImage(
image: CachedNetworkImageProvider(station.image, scale: 1.0),
colorFilter: ColorFilter.mode(
Colors.white.withOpacity(0.3), BlendMode.dstATop),
fit: BoxFit.fitWidth,
),
),
child: Text(
""
),
),
One way is to generate BorderRadius based on the index and the column count;
ex:
BorderRadius _generateBorderRadius(final int index, final int columnCount) {
if (index % columnCount == 1) {
return BorderRadius.only(
topRight: const Radius.circular(8.0),
bottomRight: const Radius.circular(8.0),
);
} else if (index % columnCount == 0) {
return BorderRadius.only(
topLeft: const Radius.circular(8.0),
bottomLeft: const Radius.circular(8.0),
);
} else {
return BorderRadius.all(const Radius.circular(8.0));
}
}
Hope this will be helpful.
Happy coding!
Related
i looking for this particular kind of curved container. Thank you for help.
Code example :
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(right: 16,left: 16,top: 16,bottom: 64),
height: MediaQuery.of(context).size.height*0.80,
width: MediaQuery.of(context).size.width-32,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(0),
bottomLeft: Radius.circular(MediaQuery.of(context).size.width*.4),
bottomRight: Radius.circular(32.0),
topRight: Radius.circular(0)),
),
);
}
}
I can't seem to find a good way to remove these small white lines, changed the container color to fit with the ModalBottomSheet default background color.
Here is a part of code:
void mountainModalBottomSheet(context){
showModalBottomSheet(context: context, builder: (BuildContext bc){
return Container(
color: Color(0xff757575),
height: MediaQuery.of(context).size.height*.60,
child:Column(
children: [
Container(
width: double.infinity,
height: 225,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(38),
topRight: Radius.circular(38),
),
image:DecorationImage(image: NetworkImage('https://hotelvilatina.hr/wp-content/uploads/2017/11/sljeme.jpg'),
fit: BoxFit.fill),
),
Update
You can use shape property but you need to make sure of providing clipBehavior:hardEdge
showModalBottomSheet(
clipBehavior: Clip.antiAlias, // or hardEdge must
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(38),
topRight: Radius.circular(38),
),
),
context: context,
backgroundColor: Colors.white,
builder: (c) {
return Container();
});
Wrap your Container with ClipRRect widget
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent, // make sure of it
builder: (c) {
return ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(38),
topRight: Radius.circular(38),
),
child: Container(
color: Colors.white,
));
});
You can use the "shape" property of showModalBottomSheet to give a radius to your bottom sheet. In this way, your bottom sheet has its own radiuses and you will no longer see your white lines.
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
backgroundColor: Colors.white,
...
);
I'm trying to make this corner transparent but nothing works I can't make it rounded too. like here
I made it black but when I give it color: Color.transparent it is not changing without color: Colors.black it's white
Help pls
import 'package:flutter/material.dart';
class SlidebarMenu extends StatelessWidget {
final padding = const EdgeInsets.symmetric(horizontal: 10);
final boxBorder = const BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(50.0),
bottomRight: Radius.circular(40.0),
topLeft: Radius.circular(40.0),
bottomLeft: Radius.circular(40.0)),
);
const SlidebarMenu({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
const string = 'Logged in as: ';
const email = 'sample#domain.com';
return SafeArea(
child: Drawer(
child: Material(
child: ListView(
children: <Widget>[
Container(
color: Colors.black,
child: buildHeader(
//end work
string: string,
email: email,
),
),
],
),
),
),
);
}
Try below code hope its help to you.
Add your drawer Widget inside ClipRRect
ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(35),
bottomRight: Radius.circular(35),
),
child: Drawer(),
),
I understand that making a widget reusable is good when you want to de-clutter your code but I think that it also reduces the code readibility and most often it's the properties (like padding,color,shape) of a widget (like Container,Material) which makes up the most clutter.
So, is there a way that I can make properties of a widget reusable rather than the widget itself.
For example, is there a way that I can make properties of this Material:
Material(
elevation: 4.0,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
bottomLeft: Radius.circular(30.0),
bottomRight: Radius.circular(5.0),
)),
color: Theme.of(context).primaryColorLight,
child: ...
Like this:
Material(
myMaterialProps: props,
child: ...
If you want to reuse your widget, the easiest way would be to create a custom widget, and set default values for the properties that won't change that often and make those properties optional.
To support variations of your widget, you can create factory methods that will receive only the properties that are different.
Here's a quick example (keep in mind it's just an example):
class MyWidget extends StatelessWidget {
final double elevation;
final Clip clipBehaviour;
final Color color;
final Widget child;
MyWidget(this.child, {double elevation, Clip clipBehaviour, Color color})
: elevation = elevation ?? 4,
clipBehaviour = clipBehaviour ?? Clip.hardEdge,
color = color ?? Colors.green;
factory MyWidget.withRedBorder(Widget child) {
return MyWidget(
child,
color: Colors.red,
);
}
#override
Widget build(BuildContext context) {
return Material(
elevation: 4.0,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
bottomLeft: Radius.circular(30.0),
bottomRight: Radius.circular(5.0),
)),
color: Theme.of(context).primaryColorLight,
child: child);
}
}
Is making your custom Widget fit your situation?
class MyCustomMaterial extends StatelessWidget{
const MyCustomMaterial({
required this.child,
Key? key,
}):super(key:key);
final Widget child;
#override
Widget build(BuildContext context){
return Material(
elevation: 4.0,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
bottomLeft: Radius.circular(30.0),
bottomRight: Radius.circular(5.0),
),
),
color: Theme.of(context).primaryColorLight,
child: child,
);
}
}
And use it as:
MyCustomMaterial(
child: ...
I am getting a warning when using following code but my app is running fine:
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during paint():
A borderRadius can only be given for uniform borders.
'package:flutter/src/painting/box_border.dart':
Failed assertion: line 510 pos 12: 'borderRadius == null'
Here is my code:
Container(
height: screenSize.height*.13,
width: AppSize.medium,
decoration: BoxDecoration(
color: Colors.red,
border: Border(
right: BorderSide(
width: 1.0,
color: Colors.blue
),
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(AppSize.small),
bottomRight: Radius.circular(AppSize.small),
)
),
)
This is the easiest way that I could came up with... as you can see there's 2 container, the color of outer container is actually the color of the border and the margin of inner container is the strokeWidth of the border and the color of inner container is the background color.
Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(15.0),
topRight: const Radius.circular(15.0),
),// BorderRadius
),// BoxDecoration
child: Container(
margin: const EdgeInsetsDirectional.only(start: 2, end: 2, top: 2),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(13.0),
topRight: const Radius.circular(13.0),
),// BorderRadius
),// BoxDecoration
),// Container
),// Container
It's a bit silly answer but works! ;)
Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
stops: [0.02, 0.02],
colors: [Colors.red, Colors.white]
),
borderRadius: new BorderRadius.all(const Radius.circular(6.0))))
Flutter is complaining because you only apply a right border to your container, but want to have a border radius as well.
Flutter expects the border to be uniform, i.e. all the way around and in the same color, when applying border radius. If you jump to the sources where the assertion error was thrown you can have a look at the actual assertion.
I was struggling with this same error, and found out a simpler solution that's much simpler than the alternatives suggested, which is using a shadow instead of a border.
If you think about it a 1pt border on one side is exactly the same as a shadow without blur that's offset 1pt in that direction.
You can create your Container with the round borders and use decoration to add a shadow to act as your desired border. Here's an example simulating a bottom border:
Container(
padding: EdgeInsets.symmetric(horizontal: 32.0, vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(46),
boxShadow: [
BoxShadow(
color: Color(0xFFEEEEEE),
blurRadius: 0,
offset: Offset(0, 1),
),
],
),
child: ...
),
All to this effect:
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.only(
topRight:
widget.currentJobIndex == 0 ? Radius.circular(7) : Radius.zero,
topLeft:
widget.currentJobIndex == 0 ? Radius.circular(7) : Radius.zero,
),
),
child: Container(
padding: EdgeInsets.only(top: 17, bottom: 20, left: 12, right: 12),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: AppColors.greyE5))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("This is the brief job description"),
SizedBox(height: 10),
Row(children: [
Text(
"Budget",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(":30,000"),
Spacer(),
Text(
"Total Bids",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(":32",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).primaryColor))
]),
SizedBox(height: 10),
Row(children: [
Text(
"Status: Confirmed",
style: TextStyle(color: Theme.of(context).primaryColor),
),
Spacer(),
Text(
"Monday August 22, 2021",
style: TextStyle(fontSize: responsiveSize(10, context)),
),
])
],
),
),
)
I used two containers, the outer one has the border radius, while the inner one has only bottom border. This way Flutter will no longer complain
Flutter expects the border to be uniform means all the way around and in the same color when applying border radius.
Check your border color are you applying the same on all sides?
Either you can apply the different color without a radius or you can use the same color with a different radius
This is the only solution that is not a workaround. Wrap your widget inside a ClipRect with an border on all sides:
ClipRect(
clipper: Customshape(),
child: Container(
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(Radius.circular(5)),
),
),
),
This CustomShape Clipper cuts the border on the left side, which is why the Offsets x value is 2. If you need to clip it on the right side, then set x to 0 and use "size.width - 2".
class CustomShape extends CustomClipper<Rect>{
#override
Rect getClip(Size size) => const Offset(2.0, 0) & Size(size.width, size.height);
#override
bool shouldReclip(covariant CustomClipper<Rect> oldClipper) => true;
}