[英]How can I draw an arc in Flutter using custom painting?
I need to create image like this in Flutter using custom painting:我需要使用自定义绘画在 Flutter 中创建这样的图像:
I have the following code:我有以下代码:
Center(
child: CustomPaint(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
),
painter: CustomWave(),
))
Can anyone help me to do this?谁能帮我做这个?
Try this:试试这个:
class Moon extends CustomPainter: class Moon扩展了 CustomPainter:
import 'package:flutter/material.dart';
class Moon extends CustomPainter {
final double width;
Moon({required this.width});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.orange
..strokeWidth = 2
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
Path path = Path();
path.arcToPoint(Offset(width, 0), radius: Radius.circular(width + 200)); //change the radius as you like
path.arcToPoint(const Offset(0, 0), radius: Radius.circular(width - 60), clockwise: false); //change the radius as you like
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(Moon oldDelegate) => false;
@override
bool shouldRebuildSemantics(Moon oldDelegate) => false;
}
use:采用:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: CustomPaint(
painter: Moon(width: MediaQuery.of(context).size.width),
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 50,
),
),
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.