gpt4 book ai didi

flutter - 带有 ClipPath 的全圆角

转载 作者:行者123 更新时间:2023-12-03 04:14:13 31 4
gpt4 key购买 nike

我想创建一个像这样的路径:

enter image description here

但实际结果边框不好:

enter image description here

现在我想知道如何使用 ClipPath 实现完全圆角。

代码是:

class MyClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final path = Path();
path.moveTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(15, size.height);
path.quadraticBezierTo(0, size.height / 2, 15, 0);
path.lineTo(size.width, 0);
return path;
}

@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}

最佳答案

看看这个..

class MyClipper extends CustomClipper<Path>{
@override
Path getClip(Size size) {
double factor = 20.0;
var path = Path();
path.lineTo(0, size.height - factor);
path.quadraticBezierTo(0, size.height, factor, size.height);
path.lineTo(size.width-factor, size.height);
path.lineTo(size.width, size.height);
path.lineTo(size.width, 0);
path.lineTo(factor, 0);
path.quadraticBezierTo(0, 0, 0, factor);
return path;
}

@override
bool shouldReclip(CustomClipper<Path> oldClipper) => true;

}

class Page extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ClipPath(
child: Container(color: Colors.blue, child: Text("Received"), padding: EdgeInsets.all(9),),
clipper: MyClipper(),
),
),
);
}
}

输出:

enter image description here

另一种实现方式

class Page extends StatelessWidget {
final radius = Radius.circular(30);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: Text("Received"),
padding: EdgeInsets.all(9),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: radius,
bottomLeft: radius
)
),
),
),
);
}
}

关于flutter - 带有 ClipPath 的全圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61630501/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com