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

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

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

  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(
    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(
    19.71 * scale + translationX,
    20.29 * scale + translationY,
  );

  path.cubicTo(
    19.66248036993731 * scale + translationX,
    20.246995035277447 * scale + translationY,
    19.61238781511671 * scale + translationX,
    20.206920991420965 * scale + translationY,
    19.560000274790386 * scale + translationX,
    20.170000283360018 * scale + translationY,
  );

  path.cubicTo(
    19.50425436452965 * scale + translationX,
    20.132153143932147 * scale + translationY,
    19.443723822571854 * scale + translationX,
    20.10188787295325 * scale + translationY,
    19.37999957199097 * scale + translationX,
    20.079999556531405 * scale + translationY,
  );

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

  path.cubicTo(
    19.00499904639031 * scale + translationX,
    19.961938492237426 * scale + translationY,
    18.803080107120675 * scale + translationX,
    19.982826658368765 * scale + translationY,
    18.619999999999997 * scale + translationX,
    20.06 * scale + translationY,
  );

  path.cubicTo(
    18.368770129444584 * scale + translationX,
    20.15092422058886 * scale + translationY,
    18.17092417862719 * scale + translationX,
    20.348770171406255 * scale + translationY,
    18.08000038316512 * scale + translationX,
    20.600000436570884 * scale + translationY,
  );

  path.cubicTo(
    18.02087116424297 * scale + translationX,
    20.724733796811517 * scale + translationY,
    17.99339434296539 * scale + translationX,
    20.8621179031994 * scale + translationY,
    17.999999266351978 * scale + translationX,
    20.999999144077307 * scale + translationY,
  );

  path.cubicTo(
    17.995214278463372 * scale + translationX,
    21.407056001281575 * scale + translationY,
    18.23765810246276 * scale + translationX,
    21.776385213142248 * scale + translationY,
    18.61304091852399 * scale + translationX,
    21.933881983635843 * scale + translationY,
  );

  path.cubicTo(
    18.98842373458522 * scale + translationX,
    22.091378754129437 * scale + translationY,
    19.42181241780433 * scale + translationX,
    22.005603910575655 * scale + translationY,
    19.708903011671048 * scale + translationX,
    21.71699261103382 * scale + translationY,
  );

  path.cubicTo(
    19.995993605537766 * scale + translationX,
    21.428381311491986 * scale + translationY,
    20.079477692062447 * scale + translationX,
    20.994545534006757 * scale + translationY,
    19.92 * scale + translationX,
    20.62 * scale + translationY,
  );

  path.cubicTo(
    19.869357068165318 * scale + translationX,
    20.498814010076828 * scale + translationY,
    19.798329875664223 * scale + translationX,
    20.387199850432246 * scale + translationY,
    19.70999894522715 * scale + translationX,
    20.28999891418868 * 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,
    15.0 * scale + translationY,
  );

  path.cubicTo(
    18.447715250169207 * scale + translationX,
    15.0 * scale + translationY,
    18.0 * scale + translationX,
    15.447715250169207 * scale + translationY,
    18.0 * scale + translationX,
    16.0 * scale + translationY,
  );

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

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

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

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

  path.cubicTo(
    20.0 * scale + translationX,
    15.447715250169207 * scale + translationY,
    19.552284749830793 * scale + translationX,
    15.0 * scale + translationY,
    19.0 * scale + translationX,
    15.0 * scale + translationY,
  );

  path.close();

  canvas.drawPath(path, paint);
}