[英]How can I draw an arc in Flutter using custom painting?
试试这个:
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;
}
采用:
@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.