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

  final translationX = (size.width - 16.076596730083192 * scale) / 2 - 4.0 * scale;
  final translationY = (size.height - 20.000000734939896 * scale) / 2 - 1.999999970089306 * scale;

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

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

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

  path.cubicTo(
    8.447715250169207 * scale + translationX,
    16.0 * scale + translationY,
    8.0 * scale + translationX,
    16.447715250169207 * scale + translationY,
    8.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    8.0 * scale + translationX,
    17.552284749830793 * scale + translationY,
    8.447715250169207 * scale + translationX,
    18.0 * scale + translationY,
    9.0 * scale + translationX,
    18.0 * scale + translationY,
  );

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

  path.cubicTo(
    15.552284749830793 * scale + translationX,
    18.0 * scale + translationY,
    16.0 * scale + translationX,
    17.552284749830793 * scale + translationY,
    16.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    16.0 * scale + translationX,
    16.447715250169207 * scale + translationY,
    15.552284749830793 * scale + translationX,
    16.0 * scale + translationY,
    15.0 * scale + translationX,
    16.0 * scale + translationY,
  );

  path.close();

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

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

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

  path.cubicTo(
    11.0 * scale + translationX,
    8.447715250169207 * scale + translationY,
    10.552284749830793 * scale + translationX,
    8.0 * scale + translationY,
    10.0 * scale + translationX,
    8.0 * scale + translationY,
  );

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

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

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

  path.close();

  path.moveTo(
    15.0 * scale + translationX,
    12.0 * scale + translationY,
  );

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

  path.cubicTo(
    8.447715250169207 * scale + translationX,
    12.0 * scale + translationY,
    8.0 * scale + translationX,
    12.447715250169207 * scale + translationY,
    8.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    8.0 * scale + translationX,
    13.552284749830793 * scale + translationY,
    8.447715250169207 * scale + translationX,
    14.0 * scale + translationY,
    9.0 * scale + translationX,
    14.0 * scale + translationY,
  );

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

  path.cubicTo(
    15.552284749830793 * scale + translationX,
    14.0 * scale + translationY,
    16.0 * scale + translationX,
    13.552284749830793 * scale + translationY,
    16.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    16.0 * scale + translationX,
    12.447715250169207 * scale + translationY,
    15.552284749830793 * scale + translationX,
    12.0 * scale + translationY,
    15.0 * scale + translationX,
    12.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    19.71 * scale + translationX,
    15.29 * scale + translationY,
  );

  path.cubicTo(
    19.614896290305705 * scale + translationX,
    15.198959370682967 * scale + translationY,
    19.502751317722428 * scale + translationX,
    15.127594388129973 * scale + translationY,
    19.380000000000003 * scale + translationX,
    15.079999999999998 * scale + translationY,
  );

  path.cubicTo(
    19.13850506790849 * scale + translationX,
    14.970472525162146 * scale + translationY,
    18.861494896639694 * scale + translationX,
    14.970472525162146 * scale + translationY,
    18.61999998262861 * scale + translationX,
    15.079999985931225 * scale + translationY,
  );

  path.cubicTo(
    18.497248682277576 * scale + translationX,
    15.127594388129973 * scale + translationY,
    18.3851037096943 * scale + translationX,
    15.198959370682967 * scale + translationY,
    18.29 * scale + translationX,
    15.29 * scale + translationY,
  );

  path.cubicTo(
    18.201668090780814 * scale + translationX,
    15.387200118005268 * scale + translationY,
    18.13064089827972 * scale + translationX,
    15.498814277649844 * scale + translationY,
    18.07999903245595 * scale + translationX,
    15.619999164101879 * scale + translationY,
  );

  path.cubicTo(
    17.923403269916808 * scale + translationX,
    15.992397095375615 * scale + translationY,
    18.006255437852516 * scale + translationX,
    16.42243930037525 * scale + translationY,
    18.29 * scale + translationX,
    16.71 * scale + translationY,
  );

  path.cubicTo(
    18.47871883080469 * scale + translationX,
    16.897186514407906 * scale + translationY,
    18.73419701534997 * scale + translationX,
    17.001536758799638 * scale + translationY,
    19.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    19.130677257271156 * scale + translationX,
    16.99842001258614 * scale + translationY,
    19.259777687412583 * scale + translationX,
    16.97124097466163 * scale + translationY,
    19.38 * scale + translationX,
    16.919999999999998 * scale + translationY,
  );

  path.cubicTo(
    19.501183849339 * scale + translationX,
    16.86935722870913 * scale + translationY,
    19.61279800898358 * scale + translationX,
    16.798330036208036 * scale + translationY,
    19.70999894522715 * scale + translationX,
    16.70999910577096 * scale + translationY,
  );

  path.cubicTo(
    19.993744562147484 * scale + translationX,
    16.42243930037525 * scale + translationY,
    20.076596730083192 * scale + translationX,
    15.992397095375615 * scale + translationY,
    19.92 * scale + translationX,
    15.620000000000001 * scale + translationY,
  );

  path.cubicTo(
    19.869357068165318 * scale + translationX,
    15.498814277649846 * scale + translationY,
    19.798329875664223 * scale + translationX,
    15.387200118005268 * scale + translationY,
    19.70999894522715 * scale + translationX,
    15.289999181761699 * scale + translationY,
  );

  path.close();

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

  path.cubicTo(
    19.989582659837488 * scale + translationX,
    8.848134430197735 * scale + translationY,
    19.96947059098943 * scale + translationX,
    8.757630120381467 * scale + translationY,
    19.939998950748507 * scale + translationX,
    8.66999954378082 * scale + translationY,
  );

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

  path.cubicTo(
    19.891919739825056 * scale + translationX,
    8.477180103356682 * scale + translationY,
    19.827784613059805 * scale + translationX,
    8.382665179702625 * scale + translationY,
    19.750000815122753 * scale + translationX,
    8.300000342557919 * scale + translationY,
  );

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

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

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

  path.cubicTo(
    13.667335730345819 * scale + translationX,
    2.2222162969886416 * scale + translationY,
    13.57282080669176 * scale + translationX,
    2.1580811702233884 * scale + translationY,
    13.470000555934355 * scale + translationX,
    2.1100000870840026 * scale + translationY,
  );

  path.cubicTo(
    13.440149499896748 * scale + translationX,
    2.10576013726435 * scale + translationY,
    13.409849899958985 * scale + translationX,
    2.10576013726435 * scale + translationY,
    13.379999700933695 * scale + translationX,
    2.1099999528378257 * scale + translationY,
  );

  path.cubicTo(
    13.278414601175177 * scale + translationX,
    2.0517413241087925 * scale + translationY,
    13.166223150411797 * scale + translationX,
    2.014344173854332 * scale + translationY,
    13.04999980483272 * scale + translationX,
    1.999999970089306 * scale + translationY,
  );

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

  path.cubicTo(
    5.343145889292691 * scale + translationX,
    2.000000010226537 * scale + translationY,
    4.000000069831183 * scale + translationX,
    3.343145829688045 * scale + translationY,
    4.0000001192092896 * scale + translationX,
    5.000000149011611 * scale + translationY,
  );

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

  path.cubicTo(
    4.000000069831183 * scale + translationX,
    20.65685488556769 * scale + translationY,
    5.343145889292691 * scale + translationX,
    22.0000007050292 * scale + translationY,
    7.000000208616255 * scale + translationX,
    22.000000655651093 * scale + translationY,
  );

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

  path.cubicTo(
    15.552284749830793 * scale + translationX,
    22.0 * scale + translationY,
    16.0 * scale + translationX,
    21.552284749830793 * scale + translationY,
    16.0 * scale + translationX,
    21.0 * scale + translationY,
  );

  path.cubicTo(
    16.0 * scale + translationX,
    20.447715250169207 * scale + translationY,
    15.552284749830793 * scale + translationX,
    20.0 * scale + translationY,
    15.0 * scale + translationX,
    20.0 * scale + translationY,
  );

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

  path.cubicTo(
    6.447715250169207 * scale + translationX,
    20.0 * scale + translationY,
    6.0 * scale + translationX,
    19.552284749830793 * scale + translationY,
    6.0 * scale + translationX,
    19.0 * scale + translationY,
  );

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

  path.cubicTo(
    6.0 * scale + translationX,
    4.447715250169207 * scale + translationY,
    6.447715250169207 * scale + translationX,
    4.0 * scale + translationY,
    7.0 * scale + translationX,
    4.0 * scale + translationY,
  );

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

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

  path.cubicTo(
    12.000000308249762 * scale + translationX,
    8.65685452793982 * scale + translationY,
    13.34314612771127 * scale + translationX,
    10.000000347401329 * scale + translationY,
    15.000000447034836 * scale + translationX,
    10.000000298023224 * scale + translationY,
  );

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

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

  path.cubicTo(
    18.0 * scale + translationX,
    12.552284749830793 * scale + translationY,
    18.447715250169207 * scale + translationX,
    13.0 * scale + translationY,
    19.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    19.552284749830793 * scale + translationX,
    13.0 * scale + translationY,
    20.0 * scale + translationX,
    12.552284749830793 * scale + translationY,
    20.0 * scale + translationX,
    12.0 * scale + translationY,
  );

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

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

  path.close();

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

  path.cubicTo(
    14.447715250169207 * scale + translationX,
    8.0 * scale + translationY,
    14.0 * scale + translationX,
    7.552284749830793 * scale + translationY,
    14.0 * scale + translationX,
    7.0 * scale + translationY,
  );

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

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

  path.close();

  path.moveTo(
    19.0 * scale + translationX,
    18.0 * scale + translationY,
  );

  path.cubicTo(
    18.447715250169207 * scale + translationX,
    18.0 * scale + translationY,
    18.0 * scale + translationX,
    18.447715250169207 * scale + translationY,
    18.0 * scale + translationX,
    19.0 * scale + translationY,
  );

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

  path.cubicTo(
    18.0 * scale + translationX,
    21.552284749830793 * scale + translationY,
    18.447715250169207 * scale + translationX,
    22.0 * scale + translationY,
    19.0 * scale + translationX,
    22.0 * scale + translationY,
  );

  path.cubicTo(
    19.552284749830793 * scale + translationX,
    22.0 * scale + translationY,
    20.0 * scale + translationX,
    21.552284749830793 * scale + translationY,
    20.0 * scale + translationX,
    21.0 * scale + translationY,
  );

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

  path.cubicTo(
    20.0 * scale + translationX,
    18.447715250169207 * scale + translationY,
    19.552284749830793 * scale + translationX,
    18.0 * scale + translationY,
    19.0 * scale + translationX,
    18.0 * scale + translationY,
  );

  path.close();

  canvas.drawPath(path, paint);
}