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

  final translationX = (size.width - 19.50000004969145 * scale) / 2 - 2.249999950308549 * scale;
  final translationY = (size.height - 19.50000004969145 * scale) / 2 - 2.249999950308549 * scale;

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

  path.moveTo(
    7.0 * scale + translationX,
    2.25 * scale + translationY,
  );

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

  path.cubicTo(
    2.588037880824501 * scale + translationX,
    2.255385766304735 * scale + translationY,
    2.2553857663047348 * scale + translationX,
    2.588037880824501 * scale + translationY,
    2.249999950308549 * scale + translationX,
    2.999999933744732 * scale + translationY,
  );

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

  path.cubicTo(
    2.2553857663047348 * scale + translationX,
    7.411961898324606 * scale + translationY,
    2.588037880824501 * scale + translationX,
    7.744614012844371 * scale + translationY,
    2.999999933744732 * scale + translationX,
    7.749999828840558 * scale + translationY,
  );

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

  path.cubicTo(
    7.411961898324606 * scale + translationX,
    7.744614012844371 * scale + translationY,
    7.744614012844371 * scale + translationX,
    7.411961898324606 * scale + translationY,
    7.749999828840558 * scale + translationX,
    6.999999845404375 * scale + translationY,
  );

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

  path.cubicTo(
    7.744614012844371 * scale + translationX,
    2.588037880824501 * scale + translationY,
    7.411961898324606 * scale + translationX,
    2.2553857663047348 * scale + translationY,
    6.999999845404375 * scale + translationX,
    2.249999950308549 * scale + translationY,
  );

  path.close();

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

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

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

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

  path.close();

  path.moveTo(
    21.0 * scale + translationX,
    2.25 * scale + translationY,
  );

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

  path.cubicTo(
    16.58803757163325 * scale + translationX,
    2.255385766304735 * scale + translationY,
    16.255385457113483 * scale + translationX,
    2.588037880824501 * scale + translationY,
    16.2499996411173 * scale + translationX,
    2.999999933744732 * scale + translationY,
  );

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

  path.cubicTo(
    16.255385457113483 * scale + translationX,
    7.411961898324606 * scale + translationY,
    16.58803757163325 * scale + translationX,
    7.744614012844371 * scale + translationY,
    16.99999962455348 * scale + translationX,
    7.749999828840558 * scale + translationY,
  );

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

  path.cubicTo(
    21.411961589133355 * scale + translationX,
    7.744614012844371 * scale + translationY,
    21.744613703653123 * scale + translationX,
    7.411961898324606 * scale + translationY,
    21.749999519649307 * scale + translationX,
    6.999999845404375 * scale + translationY,
  );

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

  path.cubicTo(
    21.744613703653123 * scale + translationX,
    2.588037880824501 * scale + translationY,
    21.411961589133355 * scale + translationX,
    2.2553857663047348 * scale + translationY,
    20.999999536213124 * scale + translationX,
    2.249999950308549 * scale + translationY,
  );

  path.close();

  path.moveTo(
    20.25 * scale + translationX,
    6.25 * scale + translationY,
  );

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

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

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

  path.close();

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

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

  path.cubicTo(
    9.588037726228874 * scale + translationX,
    2.255385766304735 * scale + translationY,
    9.25538561170911 * scale + translationX,
    2.588037880824501 * scale + translationY,
    9.249999795712924 * scale + translationX,
    2.999999933744732 * scale + translationY,
  );

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

  path.cubicTo(
    9.25538561170911 * scale + translationX,
    7.411961898324606 * scale + translationY,
    9.588037726228876 * scale + translationX,
    7.744614012844371 * scale + translationY,
    9.999999779149107 * scale + translationX,
    7.749999828840558 * scale + translationY,
  );

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

  path.cubicTo(
    14.411961743728982 * scale + translationX,
    7.744614012844371 * scale + translationY,
    14.744613858248748 * scale + translationX,
    7.411961898324606 * scale + translationY,
    14.749999674244933 * scale + translationX,
    6.999999845404375 * scale + translationY,
  );

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

  path.cubicTo(
    14.744613858248748 * scale + translationX,
    2.588037880824501 * scale + translationY,
    14.411961743728982 * scale + translationX,
    2.2553857663047348 * scale + translationY,
    13.99999969080875 * scale + translationX,
    2.249999950308549 * scale + translationY,
  );

  path.close();

  path.moveTo(
    13.25 * scale + translationX,
    6.25 * scale + translationY,
  );

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

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

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

  path.close();

  path.moveTo(
    7.0 * scale + translationX,
    9.25 * scale + translationY,
  );

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

  path.cubicTo(
    2.588037880824501 * scale + translationX,
    9.25538561170911 * scale + translationY,
    2.2553857663047348 * scale + translationX,
    9.588037726228876 * scale + translationY,
    2.249999950308549 * scale + translationX,
    9.999999779149107 * scale + translationY,
  );

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

  path.cubicTo(
    2.2553857663047348 * scale + translationX,
    14.411961743728982 * scale + translationY,
    2.588037880824501 * scale + translationX,
    14.744613858248748 * scale + translationY,
    2.999999933744732 * scale + translationX,
    14.749999674244933 * scale + translationY,
  );

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

  path.cubicTo(
    7.411961898324606 * scale + translationX,
    14.744613858248748 * scale + translationY,
    7.744614012844371 * scale + translationX,
    14.411961743728982 * scale + translationY,
    7.749999828840558 * scale + translationX,
    13.99999969080875 * scale + translationY,
  );

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

  path.cubicTo(
    7.744614012844371 * scale + translationX,
    9.588037726228876 * scale + translationY,
    7.411961898324606 * scale + translationX,
    9.25538561170911 * scale + translationY,
    6.999999845404375 * scale + translationX,
    9.249999795712924 * scale + translationY,
  );

  path.close();

  path.moveTo(
    6.25 * scale + translationX,
    13.25 * scale + translationY,
  );

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

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

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

  path.close();

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

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

  path.cubicTo(
    9.588037726228874 * scale + translationX,
    9.25538561170911 * scale + translationY,
    9.25538561170911 * scale + translationX,
    9.588037726228876 * scale + translationY,
    9.249999795712924 * scale + translationX,
    9.999999779149107 * scale + translationY,
  );

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

  path.cubicTo(
    9.25538561170911 * scale + translationX,
    14.411961743728982 * scale + translationY,
    9.588037726228876 * scale + translationX,
    14.744613858248748 * scale + translationY,
    9.999999779149107 * scale + translationX,
    14.749999674244933 * scale + translationY,
  );

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

  path.cubicTo(
    14.411961743728982 * scale + translationX,
    14.744613858248748 * scale + translationY,
    14.744613858248748 * scale + translationX,
    14.411961743728982 * scale + translationY,
    14.749999674244933 * scale + translationX,
    13.99999969080875 * scale + translationY,
  );

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

  path.cubicTo(
    14.744613858248748 * scale + translationX,
    9.588037726228876 * scale + translationY,
    14.411961743728982 * scale + translationX,
    9.25538561170911 * scale + translationY,
    13.99999969080875 * scale + translationX,
    9.249999795712924 * scale + translationY,
  );

  path.close();

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

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

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

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

  path.close();

  path.moveTo(
    21.0 * scale + translationX,
    9.25 * scale + translationY,
  );

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

  path.cubicTo(
    16.58803757163325 * scale + translationX,
    9.25538561170911 * scale + translationY,
    16.255385457113483 * scale + translationX,
    9.588037726228876 * scale + translationY,
    16.2499996411173 * scale + translationX,
    9.999999779149107 * scale + translationY,
  );

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

  path.cubicTo(
    16.255385457113483 * scale + translationX,
    14.411961743728982 * scale + translationY,
    16.58803757163325 * scale + translationX,
    14.744613858248748 * scale + translationY,
    16.99999962455348 * scale + translationX,
    14.749999674244933 * scale + translationY,
  );

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

  path.cubicTo(
    21.411961589133355 * scale + translationX,
    14.744613858248748 * scale + translationY,
    21.744613703653123 * scale + translationX,
    14.411961743728982 * scale + translationY,
    21.749999519649307 * scale + translationX,
    13.99999969080875 * scale + translationY,
  );

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

  path.cubicTo(
    21.744613703653123 * scale + translationX,
    9.588037726228876 * scale + translationY,
    21.411961589133355 * scale + translationX,
    9.25538561170911 * scale + translationY,
    20.999999536213124 * scale + translationX,
    9.249999795712924 * scale + translationY,
  );

  path.close();

  path.moveTo(
    20.25 * scale + translationX,
    13.25 * scale + translationY,
  );

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

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

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

  path.close();

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

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

  path.cubicTo(
    9.588037726228874 * scale + translationX,
    16.255385457113483 * scale + translationY,
    9.25538561170911 * scale + translationX,
    16.58803757163325 * scale + translationY,
    9.249999795712924 * scale + translationX,
    16.99999962455348 * scale + translationY,
  );

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

  path.cubicTo(
    9.25538561170911 * scale + translationX,
    21.411961589133355 * scale + translationY,
    9.588037726228876 * scale + translationX,
    21.744613703653123 * scale + translationY,
    9.999999779149107 * scale + translationX,
    21.749999519649307 * scale + translationY,
  );

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

  path.cubicTo(
    14.411961743728982 * scale + translationX,
    21.744613703653123 * scale + translationY,
    14.744613858248748 * scale + translationX,
    21.411961589133355 * scale + translationY,
    14.749999674244933 * scale + translationX,
    20.999999536213124 * scale + translationY,
  );

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

  path.cubicTo(
    14.744613858248748 * scale + translationX,
    16.58803757163325 * scale + translationY,
    14.411961743728982 * scale + translationX,
    16.255385457113483 * scale + translationY,
    13.99999969080875 * scale + translationX,
    16.2499996411173 * scale + translationY,
  );

  path.close();

  path.moveTo(
    13.25 * scale + translationX,
    20.25 * scale + translationY,
  );

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

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

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

  path.close();

  canvas.drawPath(path, paint);
}