paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size
)
override

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:

  1. Obtain an ImageStream, for example by calling ImageProvider.resolve on an AssetImage or NetworkImage object.

  2. 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.

  3. 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 / 18.0;
  final scaleY = size.height / 20.33091113799347;
  final scale = math.min(scaleX, scaleY);

  final translationX = (size.width - 18.0 * scale) / 2 - 3.0 * scale;
  final translationY = (size.height - 20.33091113799347 * scale) / 2 - 1.9999999617421333 * scale;

  final path = Path();
  final paint = Paint()..color = color;

  path.moveTo(
    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.lineTo(
    8.0 * scale + translationX,
    12.0 * scale + translationY,
  );

  path.cubicTo(
    7.447715250169207 * scale + translationX,
    12.0 * scale + translationY,
    7.0 * scale + translationX,
    12.447715250169207 * scale + translationY,
    7.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    7.0 * scale + translationX,
    13.552284749830793 * scale + translationY,
    7.447715250169207 * scale + translationX,
    14.0 * scale + translationY,
    8.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.close();

  path.moveTo(
    11.0 * scale + translationX,
    20.0 * scale + translationY,
  );

  path.lineTo(
    6.0 * scale + translationX,
    20.0 * scale + translationY,
  );

  path.cubicTo(
    5.447715250169207 * scale + translationX,
    20.0 * scale + translationY,
    5.0 * scale + translationX,
    19.552284749830793 * scale + translationY,
    5.0 * scale + translationX,
    19.0 * scale + translationY,
  );

  path.lineTo(
    5.0 * scale + translationX,
    5.0 * scale + translationY,
  );

  path.cubicTo(
    5.0 * scale + translationX,
    4.447715250169207 * scale + translationY,
    5.447715250169207 * scale + translationX,
    4.0 * scale + translationY,
    6.0 * scale + translationX,
    4.0 * scale + translationY,
  );

  path.lineTo(
    11.0 * scale + translationX,
    4.0 * scale + translationY,
  );

  path.lineTo(
    11.0 * scale + translationX,
    7.0 * scale + translationY,
  );

  path.cubicTo(
    11.00000027844744 * scale + translationX,
    8.65685452793982 * scale + translationY,
    12.343146097908948 * scale + translationX,
    10.000000347401329 * scale + translationY,
    14.000000417232513 * scale + translationX,
    10.000000298023224 * scale + translationY,
  );

  path.lineTo(
    17.0 * scale + translationX,
    10.0 * scale + translationY,
  );

  path.lineTo(
    17.0 * scale + translationX,
    11.0 * scale + translationY,
  );

  path.cubicTo(
    17.0 * scale + translationX,
    11.552284749830793 * scale + translationY,
    17.447715250169207 * scale + translationX,
    12.0 * scale + translationY,
    18.0 * scale + translationX,
    12.0 * scale + translationY,
  );

  path.cubicTo(
    18.552284749830793 * scale + translationX,
    12.0 * scale + translationY,
    19.0 * scale + translationX,
    11.552284749830793 * scale + translationY,
    19.0 * scale + translationX,
    11.0 * scale + translationY,
  );

  path.lineTo(
    19.0 * scale + translationX,
    9.0 * scale + translationY,
  );

  path.cubicTo(
    19.0 * scale + translationX,
    9.0 * scale + translationY,
    19.0 * scale + translationX,
    9.0 * scale + translationY,
    19.0 * scale + translationX,
    8.94 * scale + translationY,
  );

  path.cubicTo(
    18.990653014990066 * scale + translationX,
    8.847958945702333 * scale + translationY,
    18.970514711160682 * scale + translationX,
    8.757336578470115 * scale + translationY,
    18.93999960966432 * scale + translationX,
    8.66999982131941 * scale + translationY,
  );

  path.lineTo(
    18.94 * scale + translationX,
    8.58 * scale + translationY,
  );

  path.cubicTo(
    18.89452313294621 * scale + translationX,
    8.475722156283991 * scale + translationY,
    18.830100340505158 * scale + translationX,
    8.380783304265599 * scale + translationY,
    18.749999982507326 * scale + translationX,
    8.299999992256579 * scale + translationY,
  );

  path.lineTo(
    18.75 * scale + translationX,
    8.3 * scale + translationY,
  );

  path.lineTo(
    12.75 * scale + translationX,
    2.3000000000000007 * scale + translationY,
  );

  path.lineTo(
    12.75 * scale + translationX,
    2.3000000000000007 * scale + translationY,
  );

  path.cubicTo(
    12.66733568907378 * scale + translationX,
    2.2222162969886416 * scale + translationY,
    12.572820765419722 * scale + translationX,
    2.1580811702233884 * scale + translationY,
    12.470000514662317 * scale + translationX,
    2.1100000870840026 * scale + translationY,
  );

  path.lineTo(
    12.38 * scale + translationX,
    2.1100000000000008 * scale + translationY,
  );

  path.cubicTo(
    12.28167033248412 * scale + translationX,
    2.0525033279004905 * scale + translationY,
    12.17289855067187 * scale + translationX,
    2.0151130279025296 * scale + translationY,
    12.059999769305067 * scale + translationX,
    1.9999999617421333 * scale + translationY,
  );

  path.lineTo(
    6.0 * scale + translationX,
    2.0 * scale + translationY,
  );

  path.cubicTo(
    4.3431458594903685 * scale + translationX,
    2.000000010226537 * scale + translationY,
    3.0000000400288602 * scale + translationX,
    3.343145829688045 * scale + translationY,
    3.000000089406967 * scale + translationX,
    5.000000149011611 * scale + translationY,
  );

  path.lineTo(
    3.0 * scale + translationX,
    19.0 * scale + translationY,
  );

  path.cubicTo(
    3.0000000400288602 * scale + translationX,
    20.65685488556769 * scale + translationY,
    4.3431458594903685 * scale + translationX,
    22.0000007050292 * scale + translationY,
    6.0000001788139325 * scale + translationX,
    22.000000655651093 * scale + translationY,
  );

  path.lineTo(
    11.0 * scale + translationX,
    22.0 * scale + translationY,
  );

  path.cubicTo(
    11.552284749830793 * scale + translationX,
    22.0 * scale + translationY,
    12.0 * scale + translationX,
    21.552284749830793 * scale + translationY,
    12.0 * scale + translationX,
    21.0 * scale + translationY,
  );

  path.cubicTo(
    12.0 * scale + translationX,
    20.447715250169207 * scale + translationY,
    11.552284749830793 * scale + translationX,
    20.0 * scale + translationY,
    11.0 * scale + translationX,
    20.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    13.0 * scale + translationX,
    5.41 * scale + translationY,
  );

  path.lineTo(
    15.59 * scale + translationX,
    8.0 * scale + translationY,
  );

  path.lineTo(
    14.0 * scale + translationX,
    8.0 * scale + translationY,
  );

  path.cubicTo(
    13.447715250169207 * scale + translationX,
    8.0 * scale + translationY,
    13.0 * scale + translationX,
    7.552284749830793 * scale + translationY,
    13.0 * scale + translationX,
    7.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    20.0 * scale + translationX,
    14.0 * scale + translationY,
  );

  path.cubicTo(
    19.604744912169487 * scale + translationX,
    14.002578868223875 * scale + translationY,
    19.248096987386525 * scale + translationX,
    14.23773134610275 * scale + translationY,
    19.09 * scale + translationX,
    14.600000000000001 * scale + translationY,
  );

  path.cubicTo(
    18.4606401884444 * scale + translationX,
    14.214158566785784 * scale + translationY,
    17.738188945653057 * scale + translationX,
    14.00675629612798 * scale + translationY,
    17.0000003319671 * scale + translationX,
    14.000000273384671 * scale + translationY,
  );

  path.cubicTo(
    15.219875429678867 * scale + translationX,
    13.997442567878219 * scale + translationY,
    13.652268826175094 * scale + translationX,
    15.17157063213309 * scale + translationY,
    13.154087139637568 * scale + translationX,
    16.880565960833167 * scale + translationY,
  );

  path.cubicTo(
    12.655905453100043 * scale + translationX,
    18.589561289533247 * scale + translationY,
    13.347044239995057 * scale + translationX,
    20.42212625478518 * scale + translationY,
    14.849703592690123 * scale + translationX,
    21.376518677260393 * scale + translationY,
  );

  path.cubicTo(
    16.352362945385188 * scale + translationX,
    22.330911099735605 * scale + translationY,
    18.3049033573725 * scale + translationX,
    22.177440861005266 * scale + translationY,
    19.64 * scale + translationX,
    21.0 * scale + translationY,
  );

  path.cubicTo(
    20.05686882134176 * scale + translationX,
    20.635466461329695 * scale + translationY,
    20.099344853249622 * scale + translationX,
    20.002033839855674 * scale + translationY,
    19.734878430180867 * scale + translationX,
    19.585106340739145 * scale + translationY,
  );

  path.cubicTo(
    19.370412007112115 * scale + translationX,
    19.168178841622616 * scale + translationY,
    18.73698623592481 * scale + translationX,
    19.125600776496675 * scale + translationY,
    18.320000033711274 * scale + translationX,
    19.49000003586423 * scale + translationY,
  );

  path.cubicTo(
    17.956853887262525 * scale + translationX,
    19.8151815398747 * scale + translationY,
    17.48744864329491 * scale + translationX,
    19.99654265686219 * scale + translationY,
    17.0 * scale + translationX,
    20.0 * scale + translationY,
  );

  path.cubicTo(
    16.16776149397975 * scale + translationX,
    19.9865894316574 * scale + translationY,
    15.430829634932278 * scale + translationX,
    19.459142190040367 * scale + translationY,
    15.149729945822749 * scale + translationX,
    18.675698676423327 * scale + translationY,
  );

  path.cubicTo(
    14.86863025671322 * scale + translationX,
    17.892255162806286 * scale + translationY,
    15.102134204107125 * scale + translationX,
    17.01661536007914 * scale + translationY,
    15.736005808496904 * scale + translationX,
    16.477164191395246 * scale + translationY,
  );

  path.cubicTo(
    16.36987741288668 * scale + translationX,
    15.937713022711357 * scale + translationY,
    17.27158873045915 * scale + translationX,
    15.847237294859642 * scale + translationY,
    18.0 * scale + translationX,
    16.25 * scale + translationY,
  );

  path.lineTo(
    17.78 * scale + translationX,
    16.25 * scale + translationY,
  );

  path.cubicTo(
    17.227715250169208 * scale + translationX,
    16.25 * scale + translationY,
    16.78 * scale + translationX,
    16.697715250169207 * scale + translationY,
    16.78 * scale + translationX,
    17.25 * scale + translationY,
  );

  path.cubicTo(
    16.78 * scale + translationX,
    17.802284749830793 * scale + translationY,
    17.227715250169208 * scale + translationX,
    18.25 * scale + translationY,
    17.78 * scale + translationX,
    18.25 * scale + translationY,
  );

  path.lineTo(
    20.0 * scale + translationX,
    18.25 * scale + translationY,
  );

  path.cubicTo(
    20.552284749830793 * scale + translationX,
    18.25 * scale + translationY,
    21.0 * scale + translationX,
    17.802284749830793 * scale + translationY,
    21.0 * scale + translationX,
    17.25 * scale + translationY,
  );

  path.lineTo(
    21.0 * scale + translationX,
    15.0 * scale + translationY,
  );

  path.cubicTo(
    21.0 * scale + translationX,
    14.447715250169207 * scale + translationY,
    20.552284749830793 * scale + translationX,
    14.0 * scale + translationY,
    20.0 * scale + translationX,
    14.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    8.0 * scale + translationX,
    10.0 * scale + translationY,
  );

  path.lineTo(
    9.0 * scale + translationX,
    10.0 * scale + translationY,
  );

  path.cubicTo(
    9.552284749830793 * scale + translationX,
    10.0 * scale + translationY,
    10.0 * scale + translationX,
    9.552284749830793 * scale + translationY,
    10.0 * scale + translationX,
    9.0 * scale + translationY,
  );

  path.cubicTo(
    10.0 * scale + translationX,
    8.447715250169207 * scale + translationY,
    9.552284749830793 * scale + translationX,
    8.0 * scale + translationY,
    9.0 * scale + translationX,
    8.0 * scale + translationY,
  );

  path.lineTo(
    8.0 * scale + translationX,
    8.0 * scale + translationY,
  );

  path.cubicTo(
    7.447715250169207 * scale + translationX,
    8.0 * scale + translationY,
    7.0 * scale + translationX,
    8.447715250169207 * scale + translationY,
    7.0 * scale + translationX,
    9.0 * scale + translationY,
  );

  path.cubicTo(
    7.0 * scale + translationX,
    9.552284749830793 * scale + translationY,
    7.447715250169207 * scale + translationX,
    10.0 * scale + translationY,
    8.0 * scale + translationX,
    10.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    8.0 * scale + translationX,
    16.0 * scale + translationY,
  );

  path.cubicTo(
    7.447715250169207 * scale + translationX,
    16.0 * scale + translationY,
    7.0 * scale + translationX,
    16.447715250169207 * scale + translationY,
    7.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    7.0 * scale + translationX,
    17.552284749830793 * scale + translationY,
    7.447715250169207 * scale + translationX,
    18.0 * scale + translationY,
    8.0 * scale + translationX,
    18.0 * scale + translationY,
  );

  path.lineTo(
    10.0 * scale + translationX,
    18.0 * scale + translationY,
  );

  path.cubicTo(
    10.552284749830793 * scale + translationX,
    18.0 * scale + translationY,
    11.0 * scale + translationX,
    17.552284749830793 * scale + translationY,
    11.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    11.0 * scale + translationX,
    16.447715250169207 * scale + translationY,
    10.552284749830793 * scale + translationX,
    16.0 * scale + translationY,
    10.0 * scale + translationX,
    16.0 * scale + translationY,
  );

  path.close();

  canvas.drawPath(path, paint);
}