MyPainter.dart
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'dart:math';
import 'package:flutter/material.dart';
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
..isAntiAlias = true
..strokeWidth=1.0
..style=PaintingStyle.fill
..color=Colors.grey[700]
..invertColors=false;
Paint line = Paint()
..color = Colors.grey[700]
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke
..strokeWidth = 5;
double cx=size.width/2,cy=size.height/2;
// double radius=size.width/4;
Offset center = Offset(size.width/2, 0); // 坐标中心
double radius = min(size.width/6, size.height/6); // 半径、
canvas.drawCircle(
center,
radius,
line
);
Rect rect = Rect.fromCircle(center: center, radius: radius);
// Rect rect =Rect.fromLTRB(50.0, 50.0, size.width-50.0, size.height);
// canvas.drawRect(rect, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}