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.255727792493488;
final scaleY = size.height / 20.358509799081293;
final scale = math.min(scaleX, scaleY);
final translationX = (size.width - 20.255727792493488 * scale) / 2 - 1.9963882838175966 * scale;
final translationY = (size.height - 20.358509799081293 * scale) / 2 - 1.6414902009187042 * scale;
final path = Path();
final paint = Paint()..color = color;
path.moveTo(
12.89 * scale + translationX,
18.06 * scale + translationY,
);
path.cubicTo(
12.370863262154106 * scale + translationX,
17.87246192527585 * scale + translationY,
11.79795332410223 * scale + translationX,
18.141013458737667 * scale + translationY,
11.61 * scale + translationX,
18.66 * scale + translationY,
);
path.lineTo(
10.88 * scale + translationX,
20.66 * scale + translationY,
);
path.cubicTo(
10.69246192527585 * scale + translationX,
21.179136737845894 * scale + translationY,
10.961013458737668 * scale + translationX,
21.75204667589777 * scale + translationY,
11.48 * scale + translationX,
21.94 * scale + translationY,
);
path.cubicTo(
11.58899753289334 * scale + translationX,
21.979561071956425 * scale + translationY,
11.704045172652046 * scale + translationX,
21.999863596619726 * scale + translationY,
11.82 * scale + translationX,
21.999999999999996 * scale + translationY,
);
path.cubicTo(
12.241030075474901 * scale + translationX,
21.999820865006317 * scale + translationY,
12.616849799489906 * scale + translationX,
21.735947441761738 * scale + translationY,
12.76 * scale + translationX,
21.34 * scale + translationY,
);
path.lineTo(
13.49 * scale + translationX,
19.34 * scale + translationY,
);
path.cubicTo(
13.67753807472415 * scale + translationX,
18.820863262154106 * scale + translationY,
13.408986541262333 * scale + translationX,
18.24795332410223 * scale + translationY,
12.89 * scale + translationX,
18.06 * scale + translationY,
);
path.close();
path.moveTo(
8.89 * scale + translationX,
18.06 * scale + translationY,
);
path.cubicTo(
8.370863262154106 * scale + translationX,
17.87246192527585 * scale + translationY,
7.79795332410223 * scale + translationX,
18.141013458737667 * scale + translationY,
7.609999999999999 * scale + translationX,
18.66 * scale + translationY,
);
path.lineTo(
6.88 * scale + translationX,
20.66 * scale + translationY,
);
path.cubicTo(
6.69246192527585 * scale + translationX,
21.179136737845894 * scale + translationY,
6.961013458737667 * scale + translationX,
21.75204667589777 * scale + translationY,
7.48 * scale + translationX,
21.94 * scale + translationY,
);
path.cubicTo(
7.588997532893339 * scale + translationX,
21.979561071956425 * scale + translationY,
7.704045172652047 * scale + translationX,
21.999863596619726 * scale + translationY,
7.82 * scale + translationX,
21.999999999999996 * scale + translationY,
);
path.cubicTo(
8.241030075474901 * scale + translationX,
21.999820865006317 * scale + translationY,
8.616849799489906 * scale + translationX,
21.735947441761738 * scale + translationY,
8.76 * scale + translationX,
21.34 * scale + translationY,
);
path.lineTo(
9.49 * scale + translationX,
19.34 * scale + translationY,
);
path.cubicTo(
9.67753807472415 * scale + translationX,
18.820863262154106 * scale + translationY,
9.408986541262333 * scale + translationX,
18.24795332410223 * scale + translationY,
8.89 * scale + translationX,
18.06 * scale + translationY,
);
path.close();
path.moveTo(
8.89 * scale + translationX,
11.059999999999999 * scale + translationY,
);
path.cubicTo(
8.370863262154106 * scale + translationX,
10.872461925275852 * scale + translationY,
7.797953324102233 * scale + translationX,
11.141013458737667 * scale + translationY,
7.610000000000001 * scale + translationX,
11.659999999999998 * scale + translationY,
);
path.lineTo(
6.51 * scale + translationX,
14.659999999999998 * scale + translationY,
);
path.cubicTo(
6.399224606719728 * scale + translationX,
14.966399900399393 * scale + translationY,
6.4446611362727335 * scale + translationX,
15.30755549466647 * scale + translationY,
6.631767928937531 * scale + translationX,
15.574282199103521 * scale + translationY,
);
path.cubicTo(
6.818874721602329 * scale + translationX,
15.841008903540573 * scale + translationY,
7.1241901359518645 * scale + translationX,
15.999861399517545 * scale + translationY,
7.449999999999999 * scale + translationX,
15.999999999999998 * scale + translationY,
);
path.cubicTo(
7.871030075474901 * scale + translationX,
15.999820865006317 * scale + translationY,
8.246849799489906 * scale + translationX,
15.73594744176174 * scale + translationY,
8.39 * scale + translationX,
15.34 * scale + translationY,
);
path.lineTo(
9.49 * scale + translationX,
12.34 * scale + translationY,
);
path.cubicTo(
9.677538074724149 * scale + translationX,
11.820863262154106 * scale + translationY,
9.408986541262333 * scale + translationX,
11.24795332410223 * scale + translationY,
8.89 * scale + translationX,
11.059999999999999 * scale + translationY,
);
path.close();
path.moveTo(
12.89 * scale + translationX,
11.059999999999999 * scale + translationY,
);
path.cubicTo(
12.370863262154106 * scale + translationX,
10.872461925275852 * scale + translationY,
11.797953324102233 * scale + translationX,
11.141013458737667 * scale + translationY,
11.610000000000001 * scale + translationX,
11.659999999999998 * scale + translationY,
);
path.lineTo(
10.510000000000002 * scale + translationX,
14.659999999999998 * scale + translationY,
);
path.cubicTo(
10.399224606719729 * scale + translationX,
14.966399900399393 * scale + translationY,
10.444661136272735 * scale + translationX,
15.307555494666468 * scale + translationY,
10.631767928937533 * scale + translationX,
15.57428219910352 * scale + translationY,
);
path.cubicTo(
10.818874721602329 * scale + translationX,
15.841008903540573 * scale + translationY,
11.124190135951864 * scale + translationX,
15.999861399517545 * scale + translationY,
11.45 * scale + translationX,
15.999999999999998 * scale + translationY,
);
path.cubicTo(
11.8710300754749 * scale + translationX,
15.999820865006317 * scale + translationY,
12.246849799489905 * scale + translationX,
15.73594744176174 * scale + translationY,
12.389999999999999 * scale + translationX,
15.34 * scale + translationY,
);
path.lineTo(
13.489999999999998 * scale + translationX,
12.34 * scale + translationY,
);
path.cubicTo(
13.677538074724145 * scale + translationX,
11.820863262154107 * scale + translationY,
13.408986541262331 * scale + translationX,
11.247953324102234 * scale + translationY,
12.89 * scale + translationX,
11.06 * scale + translationY,
);
path.close();
path.moveTo(
18.42 * scale + translationX,
6.219999999999999 * scale + translationY,
);
path.cubicTo(
17.164183644168716 * scale + translationX,
3.334343727807167 * scale + translationY,
14.137017369420755 * scale + translationX,
1.6414902009187042 * scale + translationY,
11.020967054034902 * scale + translationX,
2.0823086961342177 * scale + translationY,
);
path.cubicTo(
7.904916738649047 * scale + translationX,
2.523127191349731 * scale + translationY,
5.466106711759602 * scale + translationX,
4.989236347736299 * scale + translationY,
5.060000226199626 * scale + translationX,
8.11000036254525 * scale + translationY,
);
path.cubicTo(
3.263942718131013 * scale + translationX,
8.544233775271437 * scale + translationY,
1.999067600055144 * scale + translationX,
10.152195935178344 * scale + translationY,
2.0000000000000004 * scale + translationX,
12.000000000000002 * scale + translationY,
);
path.cubicTo(
1.9963882838175966 * scale + translationX,
13.145763686492591 * scale + translationY,
2.4842846819570057 * scale + translationX,
14.23806905546142 * scale + translationY,
3.339999999999999 * scale + translationX,
15.0 * scale + translationY,
);
path.cubicTo(
3.6051659190422227 * scale + translationX,
15.254694255046847 * scale + translationY,
3.988709325334805 * scale + translationX,
15.34333588007036 * scale + translationY,
4.338741688552285 * scale + translationX,
15.230821557089858 * scale + translationY,
);
path.cubicTo(
4.688774051769766 * scale + translationX,
15.118307234109356 * scale + translationY,
4.948832370441684 * scale + translationX,
14.82278641743672 * scale + translationY,
5.015929928660699 * scale + translationX,
14.461289466057568 * scale + translationY,
);
path.cubicTo(
5.083027486879715 * scale + translationX,
14.099792514678416 * scale + translationY,
4.946340915362025 * scale + translationX,
13.73063175922889 * scale + translationY,
4.66 * scale + translationX,
13.5 * scale + translationY,
);
path.cubicTo(
4.235848046201616 * scale + translationX,
13.117221984557077 * scale + translationY,
3.995650568068663 * scale + translationX,
12.571318625164002 * scale + translationY,
4.000000000000001 * scale + translationX,
12.0 * scale + translationY,
);
path.cubicTo(
4.0 * scale + translationX,
10.895430500338414 * scale + translationY,
4.8954305003384135 * scale + translationX,
10.0 * scale + translationY,
6.0 * scale + translationX,
10.0 * scale + translationY,
);
path.cubicTo(
6.552284749830793 * scale + translationX,
10.0 * scale + translationY,
7.0 * scale + translationX,
9.552284749830793 * scale + translationY,
7.0 * scale + translationX,
9.0 * scale + translationY,
);
path.cubicTo(
7.005274849230245 * scale + translationX,
6.557687108009942 * scale + translationY,
8.774193766988434 * scale + translationX,
4.476576742448034 * scale + translationY,
11.18374898609261 * scale + translationX,
4.077873360869645 * scale + translationY,
);
path.cubicTo(
13.593304205196786 * scale + translationX,
3.679169979291256 * scale + translationY,
15.938298864134556 * scale + translationX,
5.079560832162466 * scale + translationY,
16.730000249296424 * scale + translationX,
7.390000110119582 * scale + translationY,
);
path.cubicTo(
16.84647054827955 * scale + translationX,
7.7401387154437415 * scale + translationY,
17.146298082065275 * scale + translationX,
7.997682879080195 * scale + translationY,
17.51 * scale + translationX,
8.06 * scale + translationY,
);
path.cubicTo(
18.94276502175142 * scale + translationX,
8.30714571856904 * scale + translationY,
19.99208165924083 * scale + translationX,
9.546097892954123 * scale + translationY,
20.000000596046448 * scale + translationX,
11.000000327825546 * scale + translationY,
);
path.cubicTo(
20.015295034709144 * scale + translationX,
11.736287343252572 * scale + translationY,
19.750855455602803 * scale + translationX,
12.450988908404842 * scale + translationY,
19.260001159287807 * scale + translationX,
13.000000782489174 * scale + translationY,
);
path.cubicTo(
18.928577683870888 * scale + translationX,
13.412704287445766 * scale + translationY,
18.976157483143986 * scale + translationX,
14.012184870385095 * scale + translationY,
19.368531696383748 * scale + translationX,
14.367442603994068 * scale + translationY,
);
path.cubicTo(
19.76090590962351 * scale + translationX,
14.72270033760304 * scale + translationY,
20.362151340863743 * scale + translationX,
14.710669625533892 * scale + translationY,
20.740000000000002 * scale + translationX,
14.339999999999998 * scale + translationY,
);
path.cubicTo(
21.85923137630468 * scale + translationX,
13.060983833495852 * scale + translationY,
22.252116076311083 * scale + translationX,
11.301007394575723 * scale + translationY,
21.783070651209915 * scale + translationX,
9.667435396809582 * scale + translationY,
);
path.cubicTo(
21.314025226108747 * scale + translationX,
8.03386339904344 * scale + translationY,
20.0472852540698 * scale + translationX,
6.7504128560571255 * scale + translationY,
18.42000027447939 * scale + translationX,
6.260000093281269 * scale + translationY,
);
path.close();
path.moveTo(
16.89 * scale + translationX,
18.06 * scale + translationY,
);
path.cubicTo(
16.370863262154106 * scale + translationX,
17.87246192527585 * scale + translationY,
15.797953324102231 * scale + translationX,
18.141013458737667 * scale + translationY,
15.610000000000001 * scale + translationX,
18.66 * scale + translationY,
);
path.lineTo(
14.88 * scale + translationX,
20.66 * scale + translationY,
);
path.cubicTo(
14.69246192527585 * scale + translationX,
21.179136737845894 * scale + translationY,
14.961013458737668 * scale + translationX,
21.75204667589777 * scale + translationY,
15.48 * scale + translationX,
21.94 * scale + translationY,
);
path.cubicTo(
15.58899753289334 * scale + translationX,
21.979561071956425 * scale + translationY,
15.704045172652046 * scale + translationX,
21.999863596619726 * scale + translationY,
15.82 * scale + translationX,
21.999999999999996 * scale + translationY,
);
path.cubicTo(
16.241030075474903 * scale + translationX,
21.999820865006317 * scale + translationY,
16.616849799489906 * scale + translationX,
21.73594744176174 * scale + translationY,
16.76 * scale + translationX,
21.34 * scale + translationY,
);
path.lineTo(
17.490000000000002 * scale + translationX,
19.34 * scale + translationY,
);
path.cubicTo(
17.67753807472415 * scale + translationX,
18.820863262154106 * scale + translationY,
17.408986541262333 * scale + translationX,
18.24795332410223 * scale + translationY,
16.89 * scale + translationX,
18.06 * scale + translationY,
);
path.close();
path.moveTo(
16.89 * scale + translationX,
11.059999999999999 * scale + translationY,
);
path.cubicTo(
16.370863262154106 * scale + translationX,
10.872461925275852 * scale + translationY,
15.797953324102231 * scale + translationX,
11.141013458737667 * scale + translationY,
15.61 * scale + translationX,
11.659999999999998 * scale + translationY,
);
path.lineTo(
14.510000000000002 * scale + translationX,
14.659999999999998 * scale + translationY,
);
path.cubicTo(
14.399224606719729 * scale + translationX,
14.966399900399393 * scale + translationY,
14.444661136272735 * scale + translationX,
15.307555494666468 * scale + translationY,
14.631767928937533 * scale + translationX,
15.57428219910352 * scale + translationY,
);
path.cubicTo(
14.818874721602329 * scale + translationX,
15.841008903540573 * scale + translationY,
15.124190135951864 * scale + translationX,
15.999861399517545 * scale + translationY,
15.45 * scale + translationX,
15.999999999999998 * scale + translationY,
);
path.cubicTo(
15.8710300754749 * scale + translationX,
15.999820865006319 * scale + translationY,
16.246849799489905 * scale + translationX,
15.73594744176174 * scale + translationY,
16.39 * scale + translationX,
15.34 * scale + translationY,
);
path.lineTo(
17.490000000000002 * scale + translationX,
12.34 * scale + translationY,
);
path.cubicTo(
17.67753807472415 * scale + translationX,
11.820863262154106 * scale + translationY,
17.408986541262333 * scale + translationX,
11.247953324102228 * scale + translationY,
16.89 * scale + translationX,
11.059999999999999 * scale + translationY,
);
path.close();
canvas.drawPath(path, paint);
}