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)),
),
);
}
}
Related
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 need make container with angle for chat messaging application.
enter image description here
return Container(
margin: EdgeInsets.only(left: 30, top: 100, right: 30, bottom: 50),
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
Please help, how make it?
Here you can go, make a widget and call that widget for use.
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Positioned(
top: 20,
left: 20,
child: Container(
height: 50,
width: 300,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
),
Positioned(
top: 70,
left: 300,
child: CustomPaint(painter: triangle()),
)
],
));
}
The custom paint, you can call the below widget.
class triangle extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
var paint = Paint()..color = Colors.blue;
var path = Path();
path.lineTo(-10, 0);
path.lineTo(0, 10);
path.lineTo(10, 0);
canvas.drawPath(path, paint);
}
#override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
Now just edit the path as you like to do.
Changed my answer and adapted from Flutter - ClipPath
Container(
margin:
EdgeInsets.only(left: 30, top: 100, right: 30, bottom: 50),
height: 100,
width: double.infinity,
decoration: ShapeDecoration(
color: Colors.white,
shape: MessageBorder(),
shadows: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
class MessageBorder extends ShapeBorder {
final bool usePadding;
MessageBorder({this.usePadding = true});
#override
EdgeInsetsGeometry get dimensions =>
EdgeInsets.only(bottom: usePadding ? 20 : 0);
#override
Path getInnerPath(Rect rect, {TextDirection textDirection}) => null;
#override
Path getOuterPath(Rect rect, {TextDirection textDirection}) {
rect = Rect.fromPoints(rect.topLeft, rect.bottomRight - Offset(0, 20));
return Path()
..addRRect(RRect.fromLTRBAndCorners(
rect.left, rect.top, rect.right, rect.bottom,
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomRight: Radius.circular(10)))
..moveTo(30, rect.bottomCenter.dy)
..relativeLineTo(0, 20)
..relativeLineTo(20, -20)
..close();
}
#override
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {}
#override
ShapeBorder scale(double t) => this;
}
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!