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

  final translationX = (size.width - 18.005798324341672 * scale) / 2 - 3.0 * scale;
  final translationY = (size.height - 20.02697657186813 * scale) / 2 - 2.0 * scale;

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

  path.moveTo(
    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.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.close();

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

  path.cubicTo(
    17.0 * scale + translationX,
    12.552284749830793 * scale + translationY,
    17.447715250169207 * scale + translationX,
    13.0 * scale + translationY,
    18.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    18.552284749830793 * scale + translationX,
    13.0 * scale + translationY,
    19.0 * scale + translationX,
    12.552284749830793 * scale + translationY,
    19.0 * scale + translationX,
    12.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.989582712457924 * scale + translationX,
    8.848134430197735 * scale + translationY,
    18.969470643609867 * scale + translationX,
    8.757630120381467 * scale + translationY,
    18.939999003368943 * scale + translationX,
    8.66999954378082 * scale + translationY,
  );

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

  path.cubicTo(
    18.891919698553018 * scale + translationX,
    8.477180103356682 * scale + translationY,
    18.827784571787767 * scale + translationX,
    8.382665179702625 * scale + translationY,
    18.750000773850715 * scale + translationX,
    8.300000342557919 * 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.cubicTo(
    12.436917573997391 * scale + translationX,
    2.104209420621372 * scale + translationY,
    12.403081296677941 * scale + translationX,
    2.104209420621372 * scale + translationY,
    12.369999437610863 * scale + translationX,
    2.1099999040710533 * scale + translationY,
  );

  path.cubicTo(
    12.272764641061817 * scale + translationX,
    2.0580032557343064 * scale + translationY,
    12.168263180936867 * scale + translationX,
    2.020922092464162 * scale + translationY,
    12.060000620809477 * scale + translationX,
    2.0000001029534786 * 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(
    13.0 * scale + translationX,
    22.0 * scale + translationY,
  );

  path.cubicTo(
    13.552284749830793 * scale + translationX,
    22.0 * scale + translationY,
    14.0 * scale + translationX,
    21.552284749830793 * scale + translationY,
    14.0 * scale + translationX,
    21.0 * scale + translationY,
  );

  path.cubicTo(
    14.0 * scale + translationX,
    20.447715250169207 * scale + translationY,
    13.552284749830793 * scale + translationX,
    20.0 * scale + translationY,
    13.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(
    14.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(
    14.0 * scale + translationX,
    14.0 * scale + translationY,
  );

  path.cubicTo(
    14.552284749830793 * scale + translationX,
    14.0 * scale + translationY,
    15.0 * scale + translationX,
    13.552284749830793 * scale + translationY,
    15.0 * scale + translationX,
    13.0 * scale + translationY,
  );

  path.cubicTo(
    15.0 * scale + translationX,
    12.447715250169207 * scale + translationY,
    14.552284749830793 * scale + translationX,
    12.0 * scale + translationY,
    14.0 * scale + translationX,
    12.0 * scale + translationY,
  );

  path.close();

  path.moveTo(
    20.71 * scale + translationX,
    18.29 * scale + translationY,
  );

  path.cubicTo(
    20.522233400094446 * scale + translationX,
    18.1006873491769 * scale + translationY,
    20.26663753637056 * scale + translationX,
    17.994201675658328 * scale + translationY,
    20.0 * scale + translationX,
    17.994201675658328 * scale + translationY,
  );

  path.cubicTo(
    19.73336246362944 * scale + translationX,
    17.994201675658328 * scale + translationY,
    19.477766599905557 * scale + translationX,
    18.1006873491769 * scale + translationY,
    19.29 * scale + translationX,
    18.29 * scale + translationY,
  );

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

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

  path.cubicTo(
    19.0 * scale + translationX,
    15.447715250169207 * scale + translationY,
    18.552284749830793 * scale + translationX,
    15.0 * scale + translationY,
    18.0 * scale + translationX,
    15.0 * scale + translationY,
  );

  path.cubicTo(
    17.447715250169207 * scale + translationX,
    15.0 * scale + translationY,
    17.0 * scale + translationX,
    15.447715250169207 * scale + translationY,
    17.0 * scale + translationX,
    16.0 * scale + translationY,
  );

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

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

  path.cubicTo(
    16.317878084484896 * scale + translationX,
    17.8978781456729 * scale + translationY,
    15.682122434841578 * scale + translationX,
    17.897878145672905 * scale + translationY,
    15.290000265913811 * scale + translationX,
    18.29000031460067 * scale + translationY,
  );

  path.cubicTo(
    14.897878096986046 * scale + translationX,
    18.68212248352844 * scale + translationY,
    14.897878096986046 * scale + translationX,
    19.317878133171757 * scale + translationY,
    15.290000265913813 * scale + translationX,
    19.710000302099523 * scale + translationY,
  );

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

  path.cubicTo(
    17.385103709694295 * scale + translationX,
    21.801040629317033 * scale + translationY,
    17.497248682277572 * scale + translationX,
    21.87240561187003 * scale + translationY,
    17.619999999999997 * scale + translationX,
    21.92 * scale + translationY,
  );

  path.cubicTo(
    17.86203970705545 * scale + translationX,
    22.026976571868126 * scale + translationY,
    18.137959944143237 * scale + translationX,
    22.02697657186813 * scale + translationY,
    18.379999821917554 * scale + translationX,
    21.919999787618764 * scale + translationY,
  );

  path.cubicTo(
    18.502751317722424 * scale + translationX,
    21.87240561187003 * scale + translationY,
    18.6148962903057 * scale + translationX,
    21.801040629317033 * scale + translationY,
    18.71 * scale + translationX,
    21.71 * scale + translationY,
  );

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

  path.cubicTo(
    20.8993126508231 * scale + translationX,
    19.522233400094446 * scale + translationY,
    21.005798324341672 * scale + translationX,
    19.26663753637056 * scale + translationY,
    21.005798324341672 * scale + translationX,
    19.0 * scale + translationY,
  );

  path.cubicTo(
    21.005798324341672 * scale + translationX,
    18.73336246362944 * scale + translationY,
    20.8993126508231 * scale + translationX,
    18.477766599905557 * scale + translationY,
    20.71 * scale + translationX,
    18.29 * scale + translationY,
  );

  path.close();

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

  path.cubicTo(
    12.552284749830793 * scale + translationX,
    18.0 * scale + translationY,
    13.0 * scale + translationX,
    17.552284749830793 * scale + translationY,
    13.0 * scale + translationX,
    17.0 * scale + translationY,
  );

  path.cubicTo(
    13.0 * scale + translationX,
    16.447715250169207 * scale + translationY,
    12.552284749830793 * scale + translationX,
    16.0 * scale + translationY,
    12.0 * scale + translationX,
    16.0 * scale + translationY,
  );

  path.lineTo(
    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.close();

  canvas.drawPath(path, paint);
}