[英]How to make one side circular border of widget with flutter?
I'm trying to build one side circular border with Container widget in flutter. I have searched for it but can't get any solution.我正在尝试在 flutter 中使用 Container 小部件构建一侧圆形边框。我已经搜索过它但无法获得任何解决方案。
Container(
width: 150.0,
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(30.0),
/* border: Border(
left: BorderSide()
),*/
color: Colors.white
),
child: Text("hello"),
),
Use BorderRadius.only
and provide the sides使用BorderRadius.only
并提供边
return Center(
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(40),
),
border: Border.all(
width: 3,
color: Colors.green,
style: BorderStyle.solid,
),
),
child: Center(
child: Text(
"Hello",
),
),
),
);
Output输出
You can achieve this by following code for creating your widget :您可以通过以下用于创建小部件的代码来实现此目的:
return Container(
width: 150.0,
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.zero,
bottomLeft: Radius.zero,
bottomRight: Radius.zero,
),
),
child: Text(
"hello",
),
);
This way you can have your top left sided circular border with Container widget in flutter.通过这种方式,您可以将左上角的圆形边框与颤动的容器小部件一起使用。
If you want one side of a container rounded you want to use BorderRadius.only
and specify which corners to round like this:如果您希望容器的一侧变圆,您需要使用BorderRadius.only
并指定要圆的角,如下所示:
Container(
width: 150.0,
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(40.0),
bottomRight: Radius.circular(40.0)),
color: Colors.white),
child: Text("hello"),
),
Another way of doing this is to use the ClipRRect widget.另一种方法是使用ClipRRect小部件。 Simply wrap your widget with ClipRRect and give a radius .简单地用ClipRRect包裹你的小部件并给出一个radius 。 You can specify which corner you want to make round.您可以指定要使哪个角变圆。
ClipRRect(
borderRadius: BorderRadius.only(topRight: Radius.circular(10)),
child: Container(
height: 40,
width: 40,
color: Colors.amber,
child: Text('Hello World!'),
),
);
also do can do as follows,也可以做如下,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(30.0),
bottomLeft: const Radius.circular(30.0),
),
Also You can do it with 'Shape Function'.你也可以用“形状函数”来做到这一点。
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(15.0),
topLeft: Radius.circular(15.0),
),
margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
fromLTRB= from Left, Top, Right, Bottom fromLTRB= 从左、上、右、下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.