我正在try 从这张图像复制光标,但在创建圆角时遇到了一些问题.我似乎不能把它做对.
我正在与您分享我的代码(如果您愿意,可以在DartPad中运行它).我被困在了需要转弯的地方.我试了几种方法,但似乎不管用.根据我的粗略理解,它应该使用drawRRect
来完成.
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Cursor'),
),
body: Center(
child: Transform.rotate(
angle: pi,
child: CustomPaint(
size: const Size(60, 70),
painter: CursorPainter()
)
)
),
),
)
);
}
class CursorPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.red
..style = PaintingStyle.fill;
canvas.drawPath(drawPath(size.width, size.height), paint);
}
Path drawPath(double x, double y) => Path()
..moveTo(x / 2, 0)
..lineTo(0, y)
..quadraticBezierTo(x / 2, y + 15, x, y)
..close();
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
下面是它目前的样子
如果有人有一个 idea