gpt4 book ai didi

containers - 四分之一圆形,容器呈 flutter 状

转载 作者:行者123 更新时间:2023-12-05 08:26:43 28 4
gpt4 key购买 nike

我想要一个四分之一圆形的容器,想想整个披萨的四分之一。

我如何实现这一目标?基本上我想将它放在右下角位置的另一个容器顶部,圆形部分朝内,角度当然匹配右下角形成底部容器的位置,使用堆栈小部件。

谢谢。

最佳答案

您可以使用 CustomPainter 结合 ClipRect 绘制一个圆并裁剪它。

enter image description here

enum CircleAlignment {
topLeft,
topRight,
bottomLeft,
bottomRight,
}

class QuarterCircle extends StatelessWidget {
final CircleAlignment circleAlignment;
final Color color;

const QuarterCircle({
this.color = Colors.grey,
this.circleAlignment = CircleAlignment.topLeft,
Key key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return SizedBox.expand(
child: ClipRect(
child: CustomPaint(
painter: QuarterCirclePainter(
circleAlignment: circleAlignment,
color: color,
),
),
),
);
}
}

class QuarterCirclePainter extends CustomPainter {
final CircleAlignment circleAlignment;
final Color color;

const QuarterCirclePainter({this.circleAlignment, this.color});

@override
void paint(Canvas canvas, Size size) {
final radius = math.min(size.height, size.width);
final offset = circleAlignment == CircleAlignment.topLeft
? Offset(.0, .0)
: circleAlignment == CircleAlignment.topRight
? Offset(size.width, .0)
: circleAlignment == CircleAlignment.bottomLeft
? Offset(.0, size.height)
: Offset(size.width, size.height);
canvas.drawCircle(offset, radius, Paint()..color = color);
}

@override
bool shouldRepaint(QuarterCirclePainter oldDelegate) {
return color == oldDelegate.color &&
circleAlignment == oldDelegate.circleAlignment;
}
}

你可以通过做来使用它

QuarterCircle(
circleAlignment: CircleAlignment.bottomLeft,
),

关于containers - 四分之一圆形,容器呈 flutter 状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51690562/

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