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.47727555693355;
final scaleY = size.height / 22.275500000000005;
final scale = math.min(scaleX, scaleY);
final translationX = (size.width - 20.47727555693355 * scale) / 2 - 1.54492 * scale;
final translationY = (size.height - 22.275500000000005 * scale) / 2 - 0.72747 * scale;
final path = Path();
final paint = Paint()..color = color;
path.moveTo(
10.07031 * scale + translationX,
20.50291 * scale + translationY,
);
path.cubicTo(
10.070264943591551 * scale + translationX,
20.20600337183277 * scale + translationY,
9.938297670137578 * scale + translationX,
19.924466652093304 * scale + translationY,
9.710123086949125 * scale + translationX,
19.73449341828936 * scale + translationY,
);
path.cubicTo(
9.48194850376067 * scale + translationX,
19.54452018448542 * scale + translationY,
9.18115943244264 * scale + translationX,
19.46575331073652 * scale + translationY,
8.889159943124403 * scale + translationX,
19.519509875108135 * scale + translationY,
);
path.cubicTo(
7.580079999999999 * scale + translationX,
19.75975 * scale + translationY,
5.927249999999999 * scale + translationX,
19.79588 * scale + translationY,
5.487789999999999 * scale + translationX,
18.561510000000002 * scale + translationY,
);
path.cubicTo(
5.104596103699192 * scale + translationX,
17.605518181696926 * scale + translationY,
4.469862391531065 * scale + translationX,
16.771028786524585 * scale + translationY,
3.650879886526554 * scale + translationX,
16.14650949814836 * scale + translationY,
);
path.cubicTo(
3.5924458364671343 * scale + translationX,
16.11472401319985 * scale + translationY,
3.536754215391506 * scale + translationX,
16.078138130237374 * scale + translationY,
3.48437980513122 * scale + translationX,
16.03712910310129 * scale + translationY,
);
path.cubicTo(
3.337651368777818 * scale + translationX,
15.650082924640625 * scale + translationY,
2.9676320005882335 * scale + translationX,
15.39343856911175 * scale + translationY,
2.5537099999999984 * scale + translationX,
15.391620000000001 * scale + translationY,
);
path.lineTo(
2.54883 * scale + translationX,
15.391620000000001 * scale + translationY,
);
path.cubicTo(
1.998366241539748 * scale + translationX,
15.391421569778512 * scale + translationY,
1.5513244357709821 * scale + translationX,
15.836281811535128 * scale + translationY,
1.5488299948402817 * scale + translationX,
16.386739945409783 * scale + translationY,
);
path.cubicTo(
1.54492 * scale + translationX,
17.202170000000002 * scale + translationY,
2.35983 * scale + translationX,
17.724630000000005 * scale + translationY,
2.69043 * scale + translationX,
17.901390000000003 * scale + translationY,
);
path.cubicTo(
3.0802737691252435 * scale + translationX,
18.293084106932614 * scale + translationY,
3.3935821483725923 * scale + translationX,
18.754101839088385 * scale + translationY,
3.6142601195420987 * scale + translationX,
19.260760637052048 * scale + translationY,
);
path.cubicTo(
3.9785200000000005 * scale + translationX,
20.284200000000006 * scale + translationY,
5.03711 * scale + translationX,
21.836930000000006 * scale + translationY,
8.08008 * scale + translationX,
21.636760000000006 * scale + translationY,
);
path.cubicTo(
8.08108 * scale + translationX,
21.671920000000007 * scale + translationY,
8.082030000000001 * scale + translationX,
21.705120000000004 * scale + translationY,
8.08252 * scale + translationX,
21.735390000000006 * scale + translationY,
);
path.lineTo(
8.086910000000001 * scale + translationX,
22.002970000000005 * scale + translationY,
);
path.cubicTo(
8.086910000000001 * scale + translationX,
22.555254749830798 * scale + translationY,
8.534625250169208 * scale + translationX,
23.002970000000005 * scale + translationY,
9.086910000000001 * scale + translationX,
23.002970000000005 * scale + translationY,
);
path.cubicTo(
9.639194749830795 * scale + translationX,
23.002970000000005 * scale + translationY,
10.086910000000001 * scale + translationX,
22.555254749830798 * scale + translationY,
10.086910000000001 * scale + translationX,
22.002970000000005 * scale + translationY,
);
path.lineTo(
10.082030000000001 * scale + translationX,
21.684610000000006 * scale + translationY,
);
path.cubicTo(
10.07715 * scale + translationX,
21.4951 * scale + translationY,
10.07031 * scale + translationX,
21.22068 * scale + translationY,
10.07031 * scale + translationX,
20.50291 * scale + translationY,
);
path.close();
path.moveTo(
20.73731 * scale + translationX,
5.3769100000000005 * scale + translationY,
);
path.cubicTo(
20.76905 * scale + translationX,
5.2519100000000005 * scale + translationY,
20.80031 * scale + translationX,
5.11324 * scale + translationY,
20.827650000000002 * scale + translationX,
4.95699 * scale + translationY,
);
path.cubicTo(
20.989377912605505 * scale + translationX,
3.8425779747780004 * scale + translationY,
20.848382692408393 * scale + translationX,
2.705179919588001 * scale + translationY,
20.41943854878537 * scale + translationX,
1.6639898817398202 * scale + translationY,
);
path.cubicTo(
20.309881615288415 * scale + translationX,
1.3892291051774432 * scale + translationY,
20.08451965530992 * scale + translationX,
1.1769155338711228 * scale + translationY,
19.80372003170805 * scale + translationX,
1.0839200017354802 * scale + translationY,
);
path.cubicTo(
19.44772 * scale + translationX,
0.9638 * scale + translationY,
18.13331 * scale + translationX,
0.72747 * scale + translationY,
15.619640000000002 * scale + translationX,
2.33392 * scale + translationY,
);
path.cubicTo(
13.530177703597888 * scale + translationX,
1.8422145107915415 * scale + translationY,
11.35510168447447 * scale + translationX,
1.8422145107915426 * scale + translationY,
9.265639772158432 * scale + translationX,
2.3339199426090382 * scale + translationY,
);
path.cubicTo(
6.76221 * scale + translationX,
0.7510000000000001 * scale + translationY,
5.45459 * scale + translationX,
0.9658000000000001 * scale + translationY,
5.10205 * scale + translationX,
1.07908 * scale + translationY,
);
path.cubicTo(
4.814173683202604 * scale + translationX,
1.168358753324901 * scale + translationY,
4.582105391501314 * scale + translationX,
1.3830223826169774 * scale + translationY,
4.470699937527888 * scale + translationX,
1.6630799767606599 * scale + translationY,
);
path.cubicTo(
4.033001608880823 * scale + translationX,
2.7242597466610703 * scale + translationY,
3.893540853778354 * scale + translationX,
3.8848559403934093 * scale + translationY,
4.067379921210461 * scale + translationX,
5.019519902766479 * scale + translationY,
);
path.cubicTo(
4.0918 * scale + translationX,
5.14745 * scale + translationY,
4.11816 * scale + translationX,
5.26562 * scale + translationY,
4.14551 * scale + translationX,
5.37401 * scale + translationY,
);
path.cubicTo(
3.31708025796543 * scale + translationX,
6.477450964091099 * scale + translationY,
2.8758198297223485 * scale + translationX,
7.823373127107248 * scale + translationY,
2.890139895000515 * scale + translationX,
9.203109665648785 * scale + translationY,
);
path.cubicTo(
2.8874404496872734 * scale + translationX,
9.510946025775546 * scale + translationY,
2.9016217363020336 * scale + translationX,
9.818697972375098 * scale + translationY,
2.9326201787519 * scale + translationX,
10.124980617147605 * scale + translationY,
);
path.cubicTo(
3.26662 * scale + translationX,
14.727520000000002 * scale + translationY,
6.26662 * scale + translationX,
16.109360000000002 * scale + translationY,
8.35693 * scale + translationX,
16.58398 * scale + translationY,
);
path.cubicTo(
8.31348 * scale + translationX,
16.70898 * scale + translationY,
8.27393 * scale + translationX,
16.842760000000002 * scale + translationY,
8.23877 * scale + translationX,
16.984370000000002 * scale + translationY,
);
path.cubicTo(
8.108307366317835 * scale + translationX,
17.52008389074648 * scale + translationY,
8.435975497859902 * scale + translationX,
18.060342237537537 * scale + translationY,
8.971340912685838 * scale + translationX,
18.192230799326868 * scale + translationY,
);
path.cubicTo(
9.506706327511774 * scale + translationX,
18.324119361116196 * scale + translationY,
10.047835471657754 * scale + translationX,
17.997891319615295 * scale + translationY,
10.181149461629207 * scale + translationX,
17.462879076577348 * scale + translationY,
);
path.cubicTo(
10.244777937013227 * scale + translationX,
17.129690691335504 * scale + translationY,
10.40786968148652 * scale + translationX,
16.823599932377366 * scale + translationY,
10.648930192809456 * scale + translationX,
16.584950300286994 * scale + translationY,
);
path.cubicTo(
10.946735493410227 * scale + translationX,
16.324224834740374 * scale + translationY,
11.062624847470717 * scale + translationX,
15.912320128902792 * scale + translationY,
10.944456137139902 * scale + translationX,
15.53456123574926 * scale + translationY,
);
path.cubicTo(
10.826287426809087 * scale + translationX,
15.15680234259573 * scale + translationY,
10.49632598032111 * scale + translationX,
14.884366528306817 * scale + translationY,
10.103029569484075 * scale + translationX,
14.839829367636927 * scale + translationY,
);
path.cubicTo(
6.64893 * scale + translationX,
14.445300000000003 * scale + translationY,
5.1494100000000005 * scale + translationX,
13.038080000000003 * scale + translationY,
4.923830000000001 * scale + translationX,
9.941400000000002 * scale + translationY,
);
path.cubicTo(
4.898842333445044 * scale + translationX,
9.696127974802307 * scale + translationY,
4.887594761173192 * scale + translationX,
9.449649564091036 * scale + translationY,
4.890140281357008 * scale + translationX,
9.203120529506787 * scale + translationY,
);
path.cubicTo(
4.874095615156624 * scale + translationX,
8.219774523034571 * scale + translationY,
5.198968527118294 * scale + translationX,
7.26119749799548 * scale + translationY,
5.809569805783981 * scale + translationX,
6.490229783029273 * scale + translationY,
);
path.cubicTo(
5.870923586745034 * scale + translationX,
6.409853063687071 * scale + translationY,
5.9362724625914725 * scale + translationX,
6.332605886390551 * scale + translationY,
6.005370235877514 * scale + translationX,
6.258780245830892 * scale + translationY,
);
path.cubicTo(
6.254974428817144 * scale + translationX,
5.979481739951859 * scale + translationY,
6.327535321679736 * scale + translationX,
5.58409820666799 * scale + translationY,
6.1933702799483585 * scale + translationX,
5.234370236600315 * scale + translationY,
);
path.cubicTo(
6.125905655851952 * scale + translationX,
5.053899077268292 * scale + translationY,
6.07396064407346 * scale + translationX,
4.868001706913715 * scale + translationY,
6.038099914685627 * scale + translationX,
4.678699933893053 * scale + translationY,
);
path.cubicTo(
5.956632192143555 * scale + translationX,
4.140416977431279 * scale + translationY,
5.983353519574734 * scale + translationX,
3.5912902990605815 * scale + translationY,
6.116700395035304 * scale + translationX,
3.063460197847673 * scale + translationY,
);
path.cubicTo(
6.985833691780003 * scale + translationX,
3.308932683897727 * scale + translationY,
7.803817625651621 * scale + translationX,
3.7085017468830985 * scale + translationY,
8.531699824092776 * scale + translationX,
4.243139912514624 * scale + translationY,
);
path.cubicTo(
8.775255768272821 * scale + translationX,
4.405363442439204 * scale + translationY,
9.07725403239681 * scale + translationX,
4.453828245301498 * scale + translationY,
9.359339908350517 * scale + translationX,
4.375959957149278 * scale + translationY,
);
path.cubicTo(
11.380448463714457 * scale + translationX,
3.8274595046532274 * scale + translationY,
13.511259563713699 * scale + translationX,
3.827804695464605 * scale + translationY,
15.532190129465887 * scale + translationX,
4.376960036483393 * scale + translationY,
);
path.cubicTo(
15.815855200993402 * scale + translationX,
4.454756188396948 * scale + translationY,
16.119362175674997 * scale + translationX,
4.404440888666755 * scale + translationY,
16.362749121297902 * scale + translationX,
4.239269772345392 * scale + translationY,
);
path.cubicTo(
17.08723270279317 * scale + translationX,
3.702407951850011 * scale + translationY,
17.901784089949995 * scale + translationX,
3.299267191600435 * scale + translationY,
18.76803010869516 * scale + translationX,
3.048840017657376 * scale + translationY,
);
path.cubicTo(
18.900789061704398 * scale + translationX,
3.563994157529771 * scale + translationY,
18.93049076328528 * scale + translationX,
4.100296781086028 * scale + translationY,
18.8554309460418 * scale + translationX,
4.626960232150503 * scale + translationY,
);
path.cubicTo(
18.819214577921738 * scale + translationX,
4.834497421125634 * scale + translationY,
18.762624160759067 * scale + translationX,
5.037958309537116 * scale + translationY,
18.68648034040433 * scale + translationX,
5.234390095352844 * scale + translationY,
);
path.cubicTo(
18.552319511921844 * scale + translationX,
5.584118337007493 * scale + translationY,
18.624879936601644 * scale + translationX,
5.979499319168331 * scale + translationY,
18.874479811192554 * scale + translationX,
6.258799937391227 * scale + translationY,
);
path.cubicTo(
18.95163 * scale + translationX,
6.34571 * scale + translationY,
19.02878 * scale + translationX,
6.43946 * scale + translationY,
19.098110000000002 * scale + translationX,
6.527350000000001 * scale + translationY,
);
path.cubicTo(
19.704395672654666 * scale + translationX,
7.285267855888568 * scale + translationY,
20.023778175630817 * scale + translationX,
8.23282346262937 * scale + translationY,
20.000000170896183 * scale + translationX,
9.20311007863882 * scale + translationY,
);
path.cubicTo(
20.001811472159787 * scale + translationX,
9.462718418264956 * scale + translationY,
19.98925895790005 * scale + translationX,
9.722228296846357 * scale + translationY,
19.96239991210061 * scale + translationX,
9.980449956053608 * scale + translationY,
);
path.cubicTo(
19.742189999999997 * scale + translationX,
13.03611 * scale + translationY,
18.236819999999998 * scale + translationX,
14.444320000000001 * scale + translationY,
14.766599999999999 * scale + translationX,
14.839820000000001 * scale + translationY,
);
path.cubicTo(
14.373204001388816 * scale + translationX,
14.884622959567233 * scale + translationY,
14.043288067648636 * scale + translationX,
15.157313808082566 * scale + translationY,
13.925237913796176 * scale + translationX,
15.535244857461528 * scale + translationY,
);
path.cubicTo(
13.807187759943716 * scale + translationX,
15.91317590684049 * scale + translationY,
13.923236855170757 * scale + translationX,
16.32516793309422 * scale + translationY,
14.221189999999998 * scale + translationX,
16.58592 * scale + translationY,
);
path.cubicTo(
14.469821655048118 * scale + translationX,
16.830942479358242 * scale + translationY,
14.633270503642517 * scale + translationX,
17.1492805898286 * scale + translationY,
14.687499317076874 * scale + translationX,
17.49411918657777 * scale + translationY,
);
path.cubicTo(
14.755076519956921 * scale + translationX,
17.761820456012327 * scale + translationY,
14.786121461777212 * scale + translationX,
18.03743387708762 * scale + translationY,
14.779789730627058 * scale + translationX,
18.313459666223235 * scale + translationY,
);
path.lineTo(
14.779789999999998 * scale + translationX,
20.647460000000002 * scale + translationY,
);
path.cubicTo(
14.77 * scale + translationX,
21.2949 * scale + translationY,
14.77 * scale + translationX,
21.78025 * scale + translationY,
14.77 * scale + translationX,
22.00291 * scale + translationY,
);
path.cubicTo(
14.77 * scale + translationX,
22.555194749830793 * scale + translationY,
15.217715250169206 * scale + translationX,
23.00291 * scale + translationY,
15.77 * scale + translationX,
23.00291 * scale + translationY,
);
path.cubicTo(
16.322284749830793 * scale + translationX,
23.00291 * scale + translationY,
16.77 * scale + translationX,
22.555194749830793 * scale + translationY,
16.77 * scale + translationX,
22.00291 * scale + translationY,
);
path.cubicTo(
16.77 * scale + translationX,
21.78611 * scale + translationY,
16.77 * scale + translationX,
21.31053 * scale + translationY,
16.77977 * scale + translationX,
20.66307 * scale + translationY,
);
path.lineTo(
16.77977 * scale + translationX,
18.31346 * scale + translationY,
);
path.cubicTo(
16.78782064934286 * scale + translationX,
17.87128955684407 * scale + translationY,
16.735747563925724 * scale + translationX,
17.43007621155605 * scale + translationY,
16.62497957080101 * scale + translationX,
17.001929561069478 * scale + translationY,
);
path.cubicTo(
16.5933084851132 * scale + translationX,
16.861385857678023 * scale + translationY,
16.554521892200267 * scale + translationX,
16.72254046871166 * scale + translationY,
16.50876988183292 * scale + translationX,
16.585929881280617 * scale + translationY,
);
path.cubicTo(
19.65035253439096 * scale + translationX,
16.064036180879388 * scale + translationY,
21.95373454667786 * scale + translationX,
13.34673735455197 * scale + translationY,
21.954078765480116 * scale + translationX,
10.16209942856569 * scale + translationY,
);
path.cubicTo(
21.98703279179711 * scale + translationX,
9.843525873315324 * scale + translationY,
22.002362812080626 * scale + translationX,
9.523374824715718 * scale + translationY,
21.999999561366508 * scale + translationX,
9.203109816509443 * scale + translationY,
);
path.cubicTo(
22.02219555693355 * scale + translationX,
7.821880057030863 * scale + translationY,
21.577253786160053 * scale + translationX,
6.473636369299692 * scale + translationY,
20.737299540553487 * scale + translationX,
5.3769298808711 * scale + translationY,
);
path.close();
canvas.drawPath(path, paint);
}