gpt4 book ai didi

Flutter 如何画半圆(半圆)

转载 作者:行者123 更新时间:2023-12-04 04:28:16 42 4
gpt4 key购买 nike

我怎样才能画这样的半圆?

enter image description here

代码:

class DrawHalfCircleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final Path path = new Path();
...
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}

最佳答案

创建一个 StatelessWidgetMyArc接受 diameter .

class MyArc extends StatelessWidget {
final double diameter;

const MyArc({Key key, this.diameter = 200}) : super(key: key);

@override
Widget build(BuildContext context) {
return CustomPaint(
painter: MyPainter(),
size: Size(diameter, diameter),
);
}
}

// This is the Painter class
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()..color = Colors.blue;
canvas.drawArc(
Rect.fromCenter(
center: Offset(size.height / 2, size.width / 2),
height: size.height,
width: size.width,
),
math.pi,
math.pi,
false,
paint,
);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}

用法:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: MyArc(diameter: 300),
);
}

关于Flutter 如何画半圆(半圆),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57748469/

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