paint method
Called whenever the object needs to paint. The given Canvas has its
coordinate space configured such that the origin is at the top left of the
box. The area of the box is the size of the size
argument.
Paint operations should remain inside the given area. Graphical operations outside the bounds may be silently ignored, clipped, or not clipped. It may sometimes be difficult to guarantee that a certain operation is inside the bounds (e.g., drawing a rectangle whose size is determined by user inputs). In that case, consider calling Canvas.clipRect at the beginning of paint so everything that follows will be guaranteed to only draw within the clipped area.
Implementations should be wary of correctly pairing any calls to Canvas.save/Canvas.saveLayer and Canvas.restore, otherwise all subsequent painting on this canvas may be affected, with potentially hilarious but confusing results.
To paint text on a Canvas, use a TextPainter.
To paint an image on a Canvas:
-
Obtain an ImageStream, for example by calling ImageProvider.resolve on an AssetImage or NetworkImage object.
-
Whenever the ImageStream's underlying ImageInfo object changes (see ImageStream.addListener), create a new instance of your custom paint delegate, giving it the new ImageInfo object.
-
In your delegate's paint method, call the Canvas.drawImage, Canvas.drawImageRect, or Canvas.drawImageNine methods to paint the ImageInfo.image object, applying the ImageInfo.scale value to obtain the correct rendering size.
Implementation
@override
void paint(Canvas canvas, Size size) {
final scaleX = size.width / 20.005798324341672;
final scaleY = size.height / 20.005798354252367;
final scale = math.min(scaleX, scaleY);
final translationX = (size.width - 20.005798324341672 * scale) / 2 - 2.0 * scale;
final translationY = (size.height - 20.005798354252367 * scale) / 2 - 1.999999970089306 * scale;
final path = Path();
final paint = Paint()..color = color;
path.moveTo(
12.0 * scale + translationX,
20.0 * scale + translationY,
);
path.lineTo(
5.0 * scale + translationX,
20.0 * scale + translationY,
);
path.cubicTo(
4.447715250169207 * scale + translationX,
20.0 * scale + translationY,
4.0 * scale + translationX,
19.552284749830793 * scale + translationY,
4.0 * scale + translationX,
19.0 * scale + translationY,
);
path.lineTo(
4.0 * scale + translationX,
5.0 * scale + translationY,
);
path.cubicTo(
4.0 * scale + translationX,
4.447715250169207 * scale + translationY,
4.447715250169207 * scale + translationX,
4.0 * scale + translationY,
5.0 * scale + translationX,
4.0 * scale + translationY,
);
path.lineTo(
10.0 * scale + translationX,
4.0 * scale + translationY,
);
path.lineTo(
10.0 * scale + translationX,
7.0 * scale + translationY,
);
path.cubicTo(
10.000000248645117 * scale + translationX,
8.65685452793982 * scale + translationY,
11.343146068106625 * scale + translationX,
10.000000347401329 * scale + translationY,
13.000000387430191 * scale + translationX,
10.000000298023224 * scale + translationY,
);
path.lineTo(
16.0 * scale + translationX,
10.0 * scale + translationY,
);
path.lineTo(
16.0 * scale + translationX,
11.0 * scale + translationY,
);
path.cubicTo(
16.0 * scale + translationX,
11.552284749830793 * scale + translationY,
16.447715250169207 * scale + translationX,
12.0 * scale + translationY,
17.0 * scale + translationX,
12.0 * scale + translationY,
);
path.cubicTo(
17.552284749830793 * scale + translationX,
12.0 * scale + translationY,
18.0 * scale + translationX,
11.552284749830793 * scale + translationY,
18.0 * scale + translationX,
11.0 * scale + translationY,
);
path.lineTo(
18.0 * scale + translationX,
9.0 * scale + translationY,
);
path.cubicTo(
18.0 * scale + translationX,
9.0 * scale + translationY,
18.0 * scale + translationX,
9.0 * scale + translationY,
18.0 * scale + translationX,
8.94 * scale + translationY,
);
path.cubicTo(
17.98958276507836 * scale + translationX,
8.848134430197735 * scale + translationY,
17.969470696230303 * scale + translationX,
8.757630120381467 * scale + translationY,
17.93999905598938 * scale + translationX,
8.66999954378082 * scale + translationY,
);
path.lineTo(
17.94 * scale + translationX,
8.58 * scale + translationY,
);
path.cubicTo(
17.89191965728098 * scale + translationX,
8.477180103356682 * scale + translationY,
17.82778453051573 * scale + translationX,
8.382665179702625 * scale + translationY,
17.750000732578677 * scale + translationX,
8.300000342557919 * scale + translationY,
);
path.lineTo(
17.75 * scale + translationX,
8.3 * scale + translationY,
);
path.lineTo(
11.75 * scale + translationX,
2.3000000000000007 * scale + translationY,
);
path.lineTo(
11.75 * scale + translationX,
2.3000000000000007 * scale + translationY,
);
path.cubicTo(
11.667335647801742 * scale + translationX,
2.2222162969886416 * scale + translationY,
11.572820724147684 * scale + translationX,
2.1580811702233884 * scale + translationY,
11.470000473390279 * scale + translationX,
2.1100000870840026 * scale + translationY,
);
path.cubicTo(
11.440149544600231 * scale + translationX,
2.10576013726435 * scale + translationY,
11.409849944662469 * scale + translationX,
2.10576013726435 * scale + translationY,
11.379999745637178 * scale + translationX,
2.1099999528378257 * scale + translationY,
);
path.cubicTo(
11.278414631085871 * scale + translationX,
2.0517413241087925 * scale + translationY,
11.166223180322492 * scale + translationX,
2.014344173854332 * scale + translationY,
11.049999834743414 * scale + translationX,
1.999999970089306 * scale + translationY,
);
path.lineTo(
5.0 * scale + translationX,
2.0 * scale + translationY,
);
path.cubicTo(
3.343145829688046 * scale + translationX,
2.000000010226537 * scale + translationY,
2.0000000102265374 * scale + translationX,
3.343145829688045 * scale + translationY,
2.0000000596046448 * scale + translationX,
5.000000149011611 * scale + translationY,
);
path.lineTo(
2.0 * scale + translationX,
19.0 * scale + translationY,
);
path.cubicTo(
2.000000010226538 * scale + translationX,
20.65685488556769 * scale + translationY,
3.3431458296880447 * scale + translationX,
22.0000007050292 * scale + translationY,
5.00000014901161 * scale + translationX,
22.000000655651093 * scale + translationY,
);
path.lineTo(
12.0 * scale + translationX,
22.0 * scale + translationY,
);
path.cubicTo(
12.552284749830793 * scale + translationX,
22.0 * scale + translationY,
13.0 * scale + translationX,
21.552284749830793 * scale + translationY,
13.0 * scale + translationX,
21.0 * scale + translationY,
);
path.cubicTo(
13.0 * scale + translationX,
20.447715250169207 * scale + translationY,
12.552284749830793 * scale + translationX,
20.0 * scale + translationY,
12.0 * scale + translationX,
20.0 * scale + translationY,
);
path.close();
path.moveTo(
12.0 * scale + translationX,
5.41 * scale + translationY,
);
path.lineTo(
14.59 * scale + translationX,
8.0 * scale + translationY,
);
path.lineTo(
13.0 * scale + translationX,
8.0 * scale + translationY,
);
path.cubicTo(
12.447715250169207 * scale + translationX,
8.0 * scale + translationY,
12.0 * scale + translationX,
7.552284749830793 * scale + translationY,
12.0 * scale + translationX,
7.0 * scale + translationY,
);
path.close();
path.moveTo(
7.0 * scale + translationX,
8.0 * scale + translationY,
);
path.cubicTo(
6.447715250169207 * scale + translationX,
8.0 * scale + translationY,
6.0 * scale + translationX,
8.447715250169207 * scale + translationY,
6.0 * scale + translationX,
9.0 * scale + translationY,
);
path.cubicTo(
6.0 * scale + translationX,
9.552284749830793 * scale + translationY,
6.447715250169207 * scale + translationX,
10.0 * scale + translationY,
7.0 * scale + translationX,
10.0 * scale + translationY,
);
path.lineTo(
8.0 * scale + translationX,
10.0 * scale + translationY,
);
path.cubicTo(
8.552284749830793 * scale + translationX,
10.0 * scale + translationY,
9.0 * scale + translationX,
9.552284749830793 * scale + translationY,
9.0 * scale + translationX,
9.0 * scale + translationY,
);
path.cubicTo(
9.0 * scale + translationX,
8.447715250169207 * scale + translationY,
8.552284749830793 * scale + translationX,
8.0 * scale + translationY,
8.0 * scale + translationX,
8.0 * scale + translationY,
);
path.close();
path.moveTo(
21.71 * scale + translationX,
20.29 * scale + translationY,
);
path.lineTo(
20.54 * scale + translationX,
19.13 * scale + translationY,
);
path.cubicTo(
21.308594920800005 * scale + translationX,
17.788414891064303 * scale + translationY,
21.08768648375486 * scale + translationX,
16.09887443736725 * scale + translationY,
19.999999617421334 * scale + translationX,
14.999999713066007 * scale + translationY,
);
path.lineTo(
20.0 * scale + translationX,
15.0 * scale + translationY,
);
path.cubicTo(
19.003428945177706 * scale + translationX,
13.967915392334682 * scale + translationY,
17.47676749960934 * scale + translationX,
13.650863135379023 * scale + translationY,
16.15165096568616 * scale + translationX,
14.200786496957141 * scale + translationY,
);
path.cubicTo(
14.82653443176298 * scale + translationX,
14.750709858535261 * scale + translationY,
13.972962118570411 * scale + translationX,
16.055559125376707 * scale + translationY,
13.999999412407504 * scale + translationX,
17.489999265929086 * scale + translationY,
);
path.cubicTo(
13.993000215513018 * scale + translationX,
18.717354422952152 * scale + translationY,
14.636743062567438 * scale + translationX,
19.856558486338802 * scale + translationY,
15.691739206473743 * scale + translationX,
20.483797909129102 * scale + translationY,
);
path.cubicTo(
16.746735350380046 * scale + translationX,
21.1110373319194 * scale + translationY,
18.055067637068795 * scale + translationX,
21.1324237476588 * scale + translationY,
19.130000769626925 * scale + translationX,
20.540000826353218 * scale + translationY,
);
path.lineTo(
20.29 * scale + translationX,
21.71 * scale + translationY,
);
path.cubicTo(
20.477766599905554 * scale + translationX,
21.8993126508231 * scale + translationY,
20.73336246362944 * scale + translationX,
22.005798324341672 * scale + translationY,
21.0 * scale + translationX,
22.005798324341672 * scale + translationY,
);
path.cubicTo(
21.26663753637056 * scale + translationX,
22.005798324341672 * scale + translationY,
21.522233400094446 * scale + translationX,
21.8993126508231 * scale + translationY,
21.71 * scale + translationX,
21.71 * scale + translationY,
);
path.cubicTo(
21.8993126508231 * scale + translationX,
21.522233400094446 * scale + translationY,
22.005798324341672 * scale + translationX,
21.26663753637056 * scale + translationY,
22.005798324341672 * scale + translationX,
21.0 * scale + translationY,
);
path.cubicTo(
22.005798324341672 * scale + translationX,
20.73336246362944 * scale + translationY,
21.8993126508231 * scale + translationX,
20.477766599905557 * scale + translationY,
21.71 * scale + translationX,
20.29 * scale + translationY,
);
path.close();
path.moveTo(
18.54 * scale + translationX,
18.54 * scale + translationY,
);
path.cubicTo(
17.947148919253145 * scale + translationX,
19.097516282827442 * scale + translationY,
17.022849881013425 * scale + translationX,
19.09751628282744 * scale + translationY,
16.4299994363277 * scale + translationX,
18.53999936393887 * scale + translationY,
);
path.cubicTo(
16.15471561115148 * scale + translationX,
18.259802629575926 * scale + translationY,
16.000324633991013 * scale + translationX,
17.88280140627711 * scale + translationY,
16.00000047683716 * scale + translationX,
17.490000521242617 * scale + translationY,
);
path.cubicTo(
15.99581901877281 * scale + translationX,
17.09141812529883 * scale + translationY,
16.154784489074416 * scale + translationX,
16.708455855935867 * scale + translationY,
16.440000664721456 * scale + translationX,
16.430000664317124 * scale + translationY,
);
path.cubicTo(
16.70660655184035 * scale + translationX,
16.16483833857733 * scale + translationY,
17.064146050675756 * scale + translationX,
16.011096354078106 * scale + translationY,
17.440000598979648 * scale + translationX,
16.00000054952261 * scale + translationY,
);
path.cubicTo(
17.84871422796061 * scale + translationX,
15.974880515917189 * scale + translationY,
18.249382727621644 * scale + translationX,
16.12137853796447 * scale + translationY,
18.545499956251863 * scale + translationX,
16.404208455053592 * scale + translationY,
);
path.cubicTo(
18.841617184882082 * scale + translationX,
16.687038372142712 * scale + translationY,
19.006342614018266 * scale + translationX,
17.080564038497894 * scale + translationY,
19.00000018859396 * scale + translationX,
17.4900001736057 * scale + translationY,
);
path.cubicTo(
18.991728964365528 * scale + translationX,
17.887098517277742 * scale + translationY,
18.82630105786668 * scale + translationX,
18.264705695155545 * scale + translationY,
18.540000552535055 * scale + translationX,
18.540000552535055 * scale + translationY,
);
path.close();
path.moveTo(
13.0 * scale + translationX,
12.0 * scale + translationY,
);
path.lineTo(
7.0 * scale + translationX,
12.0 * scale + translationY,
);
path.cubicTo(
6.447715250169207 * scale + translationX,
12.0 * scale + translationY,
6.0 * scale + translationX,
12.447715250169207 * scale + translationY,
6.0 * scale + translationX,
13.0 * scale + translationY,
);
path.cubicTo(
6.0 * scale + translationX,
13.552284749830793 * scale + translationY,
6.447715250169207 * scale + translationX,
14.0 * scale + translationY,
7.0 * scale + translationX,
14.0 * scale + translationY,
);
path.lineTo(
13.0 * scale + translationX,
14.0 * scale + translationY,
);
path.cubicTo(
13.552284749830793 * scale + translationX,
14.0 * scale + translationY,
14.0 * scale + translationX,
13.552284749830793 * scale + translationY,
14.0 * scale + translationX,
13.0 * scale + translationY,
);
path.cubicTo(
14.0 * scale + translationX,
12.447715250169207 * scale + translationY,
13.552284749830793 * scale + translationX,
12.0 * scale + translationY,
13.0 * scale + translationX,
12.0 * scale + translationY,
);
path.close();
path.moveTo(
11.0 * scale + translationX,
18.0 * scale + translationY,
);
path.cubicTo(
11.552284749830793 * scale + translationX,
18.0 * scale + translationY,
12.0 * scale + translationX,
17.552284749830793 * scale + translationY,
12.0 * scale + translationX,
17.0 * scale + translationY,
);
path.cubicTo(
12.0 * scale + translationX,
16.447715250169207 * scale + translationY,
11.552284749830793 * scale + translationX,
16.0 * scale + translationY,
11.0 * scale + translationX,
16.0 * scale + translationY,
);
path.lineTo(
7.0 * scale + translationX,
16.0 * scale + translationY,
);
path.cubicTo(
6.447715250169207 * scale + translationX,
16.0 * scale + translationY,
6.0 * scale + translationX,
16.447715250169207 * scale + translationY,
6.0 * scale + translationX,
17.0 * scale + translationY,
);
path.cubicTo(
6.0 * scale + translationX,
17.552284749830793 * scale + translationY,
6.447715250169207 * scale + translationX,
18.0 * scale + translationY,
7.0 * scale + translationX,
18.0 * scale + translationY,
);
path.close();
canvas.drawPath(path, paint);
}