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 / 22.060565495915913;
final scaleY = size.height / 21.034051557876012;
final scale = math.min(scaleX, scaleY);
final translationX = (size.width - 22.060565495915913 * scale) / 2 - 0.9780581463833826 * scale;
final translationY = (size.height - 21.034051557876012 * scale) / 2 - 0.9679484421239881 * scale;
final path = Path();
final paint = Paint()..color = color;
path.moveTo(
21.95117 * scale + translationX,
15.61426 * scale + translationY,
);
path.cubicTo(
20.703953275012886 * scale + translationX,
15.323963299598596 * scale + translationY,
19.628001276117303 * scale + translationX,
14.53981795345704 * scale + translationY,
18.96972989929123 * scale + translationX,
13.441409928640635 * scale + translationY,
);
path.cubicTo(
18.660149533558297 * scale + translationX,
12.984049213787625 * scale + translationY,
18.038420810696557 * scale + translationX,
12.86424956976612 * scale + translationY,
17.581060012240652 * scale + translationX,
13.17383001809272 * scale + translationY,
);
path.cubicTo(
17.123699213784747 * scale + translationX,
13.483410466419322 * scale + translationY,
17.00389956976324 * scale + translationX,
14.105139189281061 * scale + translationY,
17.31348001808984 * scale + translationX,
14.562499987736969 * scale + translationY,
);
path.cubicTo(
17.932984227356023 * scale + translationX,
15.507607687678778 * scale + translationY,
18.753229603804435 * scale + translationX,
16.30451932742611 * scale + translationY,
19.715818643345823 * scale + translationX,
16.89649883734446 * scale + translationY,
);
path.cubicTo(
19.58105 * scale + translationX,
16.9219 * scale + translationY,
19.43457 * scale + translationX,
16.94631 * scale + translationY,
19.27441 * scale + translationX,
16.9717 * scale + translationY,
);
path.cubicTo(
18.690617977458963 * scale + translationX,
17.095889881767963 * scale + translationY,
18.25493116742661 * scale + translationX,
17.584543142599475 * scale + translationY,
18.198239893042764 * scale + translationX,
18.178699893157606 * scale + translationY,
);
path.cubicTo(
17.53160840113719 * scale + translationX,
18.065039577285283 * scale + translationY,
16.850657649051527 * scale + translationX,
18.063717999124982 * scale + translationY,
16.18358994980893 * scale + translationX,
18.17478994363351 * scale + translationY,
);
path.cubicTo(
15.46429571195216 * scale + translationX,
18.3335647704979 * scale + translationY,
14.793129840035 * scale + translationX,
18.661284302420846 * scale + translationY,
14.22558974053209 * scale + translationX,
19.130849651062512 * scale + translationY,
);
path.cubicTo(
13.641742882877379 * scale + translationX,
19.6485711806261 * scale + translationY,
12.901004499568383 * scale + translationX,
19.95531882187345 * scale + translationY,
12.122069834967224 * scale + translationX,
20.001939727688775 * scale + translationY,
);
path.lineTo(
11.861329999999999 * scale + translationX,
20.001939999999998 * scale + translationY,
);
path.cubicTo(
11.08149354793108 * scale + translationX,
19.955157283138554 * scale + translationY,
10.33999308865948 * scale + translationX,
19.64770578729957 * scale + translationY,
9.755859223692251 * scale + translationX,
19.128938477843633 * scale + translationY,
);
path.cubicTo(
9.196381926829902 * scale + translationX,
18.665519350817927 * scale + translationY,
8.535651647808715 * scale + translationX,
18.34033910316406 * scale + translationY,
7.82714977138719 * scale + translationX,
18.17971946901275 * scale + translationY,
);
path.cubicTo(
7.151328932358455 * scale + translationX,
18.071766667138583 * scale + translationY,
6.462553547590147 * scale + translationX,
18.073083443609466 * scale + translationY,
5.787150077422789 * scale + translationX,
18.183620243267686 * scale + translationY,
);
path.cubicTo(
5.733050379452727 * scale + translationX,
17.59246868041208 * scale + translationY,
5.303847584655392 * scale + translationX,
17.10368243880759 * scale + translationY,
4.724649915649794 * scale + translationX,
16.973619696966267 * scale + translationY,
);
path.cubicTo(
4.567419999999998 * scale + translationX,
16.949209999999997 * scale + translationY,
4.422889999999998 * scale + translationX,
16.924789999999998 * scale + translationY,
4.290079999999998 * scale + translationX,
16.899399999999996 * scale + translationY,
);
path.cubicTo(
4.969806802583674 * scale + translationX,
16.506198813802268 * scale + translationY,
5.576941226922913 * scale + translationX,
15.999159780260651 * scale + translationY,
6.08500039885513 * scale + translationX,
15.400401009454155 * scale + translationY,
);
path.cubicTo(
6.319464080767931 * scale + translationX,
15.128452739679014 * scale + translationY,
6.531734888354062 * scale + translationX,
14.838134948488543 * scale + translationY,
6.719770115982033 * scale + translationX,
14.532240250823872 * scale + translationY,
);
path.cubicTo(
7.012005000482794 * scale + translationX,
14.064126541492438 * scale + translationY,
6.869733886324899 * scale + translationX,
13.447764237598559 * scale + translationY,
6.401892006008829 * scale + translationX,
13.155094000611317 * scale + translationY,
);
path.cubicTo(
5.9340501256927585 * scale + translationX,
12.862423763624077 * scale + translationY,
5.3175556897168965 * scale + translationX,
13.004121223008156 * scale + translationY,
5.024450200943492 * scale + translationX,
13.471690538775077 * scale + translationY,
);
path.cubicTo(
4.891233759352043 * scale + translationX,
13.688400429399184 * scale + translationY,
4.74136875277711 * scale + translationX,
13.894424692520591 * scale + translationY,
4.576209928840418 * scale + translationX,
14.087899780934645 * scale + translationY,
);
path.cubicTo(
3.93711827315708 * scale + translationX,
14.888135353638756 * scale + translationY,
3.030675610689447 * scale + translationX,
15.430822770601196 * scale + translationY,
2.02347996985188 * scale + translationX,
15.616219767331696 * scale + translationY,
);
path.cubicTo(
1.4189326260926867 * scale + translationX,
15.712008345869076 * scale + translationY,
0.9780581463833826 * scale + translationX,
16.23961244146819 * scale + translationY,
0.9912100069611877 * scale + translationX,
16.85156011834714 * scale + translationY,
);
path.cubicTo(
0.9908739817767266 * scale + translationX,
17.035510899101375 * scale + translationY,
1.0301793263339176 * scale + translationX,
17.217374859283083 * scale + translationY,
1.1064499725287948 * scale + translationX,
17.384769568366774 * scale + translationY,
);
path.cubicTo(
1.42188 * scale + translationX,
18.10059 * scale + translationY,
2.26172 * scale + translationX,
18.55277 * scale + translationY,
3.89062 * scale + translationX,
18.859379999999998 * scale + translationY,
);
path.lineTo(
3.9218800000000003 * scale + translationX,
18.989259999999998 * scale + translationY,
);
path.cubicTo(
3.9502 * scale + translationX,
19.107419999999998 * scale + translationY,
3.97949 * scale + translationX,
19.227539999999998 * scale + translationY,
4.01367 * scale + translationX,
19.33691 * scale + translationY,
);
path.cubicTo(
4.1714351292230845 * scale + translationX,
19.908661726273674 * scale + translationY,
4.699104039177238 * scale + translationX,
20.298873859352916 * scale + translationY,
5.291989834163205 * scale + translationX,
20.282229364409226 * scale + translationY,
);
path.cubicTo(
5.495554849373001 * scale + translationX,
20.2770372584283 * scale + translationY,
5.697797346853479 * scale + translationX,
20.24786256814881 * scale + translationY,
5.8945302842754215 * scale + translationX,
20.195310973958946 * scale + translationY,
);
path.cubicTo(
6.417637606874914 * scale + translationX,
20.089313883756816 * scale + translationY,
6.9550459741113295 * scale + translationX,
20.073788986152763 * scale + translationY,
7.483400134400892 * scale + translationX,
20.149410361880783 * scale + translationY,
);
path.cubicTo(
7.897735617162531 * scale + translationX,
20.27208541511707 * scale + translationY,
8.280776687771043 * scale + translationX,
20.482591731281858 * scale + translationY,
8.606449836630837 * scale + translationX,
20.76659960580471 * scale + translationY,
);
path.cubicTo(
9.525772786490794 * scale + translationX,
21.525575975060445 * scale + translationY,
10.66993275161605 * scale + translationX,
21.95984550908804 * scale + translationY,
11.861329159672728 * scale + translationX,
22.001998441247263 * scale + translationY,
);
path.lineTo(
12.12207 * scale + translationX,
22.002 * scale + translationY,
);
path.cubicTo(
13.320906705260612 * scale + translationX,
21.957976482114663 * scale + translationY,
14.471644103539047 * scale + translationX,
21.51925749748336 * scale + translationY,
15.39551018357499 * scale + translationX,
20.754000247469246 * scale + translationY,
);
path.cubicTo(
15.722740455548065 * scale + translationX,
20.469181365898567 * scale + translationY,
16.109417758988194 * scale + translationX,
20.260993373735126 * scale + translationY,
16.527339246833073 * scale + translationX,
20.144619081990104 * scale + translationY,
);
path.cubicTo(
16.73333593646517 * scale + translationX,
20.108352659079312 * scale + translationY,
16.942178881392117 * scale + translationX,
20.090704760864572 * scale + translationY,
17.151339819252314 * scale + translationX,
20.091889788263614 * scale + translationY,
);
path.cubicTo(
17.47269133387965 * scale + translationX,
20.09132657091109 * scale + translationY,
17.793079020317375 * scale + translationX,
20.127032548781457 * scale + translationY,
18.106420790309294 * scale + translationX,
20.198330881617004 * scale + translationY,
);
path.cubicTo(
18.3094222596003 * scale + translationX,
20.23622163077022 * scale + translationY,
18.51518447144755 * scale + translationX,
20.25745236595554 * scale + translationY,
18.721648538816183 * scale + translationX,
20.261808418610062 * scale + translationY,
);
path.cubicTo(
19.299612586460384 * scale + translationX,
20.277396407447046 * scale + translationY,
19.81356859786891 * scale + translationX,
19.89646581029307 * scale + translationY,
19.96677084614734 * scale + translationX,
19.33896081954214 * scale + translationY,
);
path.cubicTo(
20.00485 * scale + translationX,
19.216889999999992 * scale + translationY,
20.03415 * scale + translationX,
19.09969999999999 * scale + translationY,
20.06149 * scale + translationX,
18.984469999999995 * scale + translationY,
);
path.lineTo(
20.09274 * scale + translationX,
18.860469999999996 * scale + translationY,
);
path.cubicTo(
21.716739999999998 * scale + translationX,
18.554809999999996 * scale + translationY,
22.55954 * scale + translationX,
18.105589999999996 * scale + translationY,
22.860319999999998 * scale + translationX,
17.420039999999997 * scale + translationY,
);
path.cubicTo(
22.936414719448337 * scale + translationX,
17.271114916321025 * scale + translationY,
22.97971996377766 * scale + translationX,
17.107615454876413 * scale + translationY,
22.987318493427047 * scale + translationX,
16.940548889728145 * scale + translationY,
);
path.cubicTo(
23.038623642299296 * scale + translationX,
16.296500600426185 * scale + translationY,
22.588492198250474 * scale + translationX,
15.720324532359287 * scale + translationY,
21.951168951890132 * scale + translationX,
15.614259254460698 * scale + translationY,
);
path.close();
path.moveTo(
3.80176 * scale + translationX,
11.14844 * scale + translationY,
);
path.cubicTo(
4.221110383568307 * scale + translationX,
11.227852320337405 * scale + translationY,
4.6448565031267295 * scale + translationX,
11.033600592793768 * scale + translationY,
4.858400080025288 * scale + translationX,
10.664060175653404 * scale + translationY,
);
path.cubicTo(
5.254487344724682 * scale + translationX,
10.865653125608032 * scale + translationY,
5.688874106617526 * scale + translationX,
10.9808240227102 * scale + translationY,
6.132809820527698 * scale + translationX,
11.001949678035798 * scale + translationY,
);
path.cubicTo(
6.603829265980042 * scale + translationX,
11.008182038923737 * scale + translationY,
7.0584113088003955 * scale + translationX,
10.8289539553864 * scale + translationY,
7.398439814881512 * scale + translationX,
10.50294973720268 * scale + translationY,
);
path.cubicTo(
7.616227752990414 * scale + translationX,
10.299832059575293 * scale + translationY,
7.732207219047682 * scale + translationX,
10.010249954059356 * scale + translationY,
7.714840522392736 * scale + translationX,
9.712950657690184 * scale + translationY,
);
path.lineTo(
7.678709999999999 * scale + translationX,
9.11139 * scale + translationY,
);
path.cubicTo(
7.514909509242712 * scale + translationX,
7.924515145415363 * scale + translationY,
7.5678642093267 * scale + translationX,
6.717765319629142 * scale + translationY,
7.835000475335453 * scale + translationX,
5.549800336696457 * scale + translationY,
);
path.cubicTo(
8.524963031286187 * scale + translationX,
3.981365041061047 * scale + translationY,
10.087542959386273 * scale + translationX,
2.9790226295822286 * scale + translationY,
11.80081956358692 * scale + translationX,
3.005859888838519 * scale + translationY,
);
path.lineTo(
12.18852 * scale + translationX,
3.0019500000000003 * scale + translationY,
);
path.cubicTo(
13.900072739263644 * scale + translationX,
2.9791003021954667 * scale + translationY,
15.459386951516155 * scale + translationX,
3.981975600402961 * scale + translationY,
16.148519566604612 * scale + translationX,
5.548829851080017 * scale + translationY,
);
path.cubicTo(
16.415656823024566 * scale + translationX,
6.717764644693224 * scale + translationY,
16.46859669278047 * scale + translationX,
7.92545436470246 * scale + translationY,
16.304770585234216 * scale + translationX,
9.11328032710693 * scale + translationY,
);
path.lineTo(
16.295 * scale + translationX,
9.27637 * scale + translationY,
);
path.lineTo(
16.267660000000003 * scale + translationX,
9.71973 * scale + translationY,
);
path.cubicTo(
16.256443020690327 * scale + translationX,
10.011798056939028 * scale + translationY,
16.370083032985654 * scale + translationX,
10.294832598922065 * scale + translationY,
16.580159926184695 * scale + translationX,
10.498049953262404 * scale + translationY,
);
path.cubicTo(
16.916702575955327 * scale + translationX,
10.822555843869344 * scale + translationY,
17.36655325787441 * scale + translationX,
11.002987619495439 * scale + translationY,
17.834059156676958 * scale + translationX,
11.000979479794283 * scale + translationY,
);
path.cubicTo(
18.267990974136154 * scale + translationX,
10.963084026611801 * scale + translationY,
18.689983415761677 * scale + translationX,
10.838909005761906 * scale + translationY,
19.075280832793286 * scale + translationX,
10.635740464337761 * scale + translationY,
);
path.cubicTo(
19.234854140445353 * scale + translationX,
10.999304943650793 * scale + translationY,
19.594239256532187 * scale + translationX,
11.234176456635751 * scale + translationY,
19.991281333493315 * scale + translationX,
11.234380749375255 * scale + translationY,
);
path.lineTo(
20.008860000000002 * scale + translationX,
11.23438 * scale + translationY,
);
path.cubicTo(
20.561133072613117 * scale + translationX,
11.22464128103037 * scale + translationY,
21.00095990123198 * scale + translationX,
10.769073413655951 * scale + translationY,
20.991281576753373 * scale + translationX,
10.216800767431707 * scale + translationY,
);
path.cubicTo(
20.938124437396713 * scale + translationX,
9.532879281487817 * scale + translationY,
20.465306594447004 * scale + translationX,
8.954123600722133 * scale + translationY,
19.80573079346993 * scale + translationX,
8.765620351173919 * scale + translationY,
);
path.cubicTo(
19.331909753960826 * scale + translationX,
8.571597998141813 * scale + translationY,
18.800113385190656 * scale + translationX,
8.575469707360726 * scale + translationY,
18.329169202101912 * scale + translationX,
8.776369617950571 * scale + translationY,
);
path.cubicTo(
18.504382108750228 * scale + translationX,
7.419248411669047 * scale + translationY,
18.38344396822871 * scale + translationX,
6.040275904721155 * scale + translationY,
17.974679969734215 * scale + translationX,
4.734369992028259 * scale + translationY,
);
path.cubicTo(
16.968601811555462 * scale + translationX,
2.4383032622239416 * scale + translationY,
14.685362875576136 * scale + translationX,
0.9679484421239881 * scale + translationY,
12.178779728813526 * scale + translationX,
1.0019399776896698 * scale + translationY,
);
path.lineTo(
11.786200000000006 * scale + translationX,
1.0058499999999986 * scale + translationY,
);
path.cubicTo(
9.285984325532766 * scale + translationX,
0.9752951382524144 * scale + translationY,
7.0103359508648655 * scale + translationX,
2.4442977905350003 * scale + translationY,
6.008790304454778 * scale + translationX,
4.735350239931822 * scale + translationY,
);
path.cubicTo(
5.596962971966445 * scale + translationX,
6.0587947042579415 * scale + translationY,
5.477020325602588 * scale + translationX,
7.455804467443399 * scale + translationY,
5.657229769682315 * scale + translationX,
8.830079640508949 * scale + translationY,
);
path.cubicTo(
5.62305 * scale + translationX,
8.81445 * scale + translationY,
5.58594 * scale + translationX,
8.79688 * scale + translationY,
5.5459000000000005 * scale + translationX,
8.77832 * scale + translationY,
);
path.cubicTo(
5.051884946981428 * scale + translationX,
8.578412692217007 * scale + translationY,
4.496788320910165 * scale + translationX,
8.594158230250947 * scale + translationY,
4.014899457114028 * scale + translationX,
8.821747302918308 * scale + translationY,
);
path.cubicTo(
3.5330105933178895 * scale + translationX,
9.049336375585666 * scale + translationY,
3.1682242934457077 * scale + translationX,
9.468038109125475 * scale + translationY,
3.0087899527168145 * scale + translationX,
9.97655984321819 * scale + translationY,
);
path.cubicTo(
2.9047439462612425 * scale + translationX,
10.51901836923192 * scale + translationY,
3.2595118872685545 * scale + translationX,
11.043307377274656 * scale + translationY,
3.8017601778347254 * scale + translationX,
11.148440521489986 * scale + translationY,
);
path.close();
canvas.drawPath(path, paint);
}