paint method
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:
-
Obtain an
ImageStream, for example by callingImageProvider.resolveon anAssetImageorNetworkImageobject. -
Whenever the
ImageStream's underlyingImageInfoobject changes (seeImageStream.addListener), create a new instance of your custom paint delegate, giving it the newImageInfoobject. -
In your delegate's paint method, call the Canvas.drawImage, Canvas.drawImageRect, or Canvas.drawImageNine methods to paint the
ImageInfo.imageobject, applying theImageInfo.scalevalue to obtain the correct rendering size.
Implementation
@override
void paint(Canvas canvas, Size size) {
Paint paint0Fill = Paint()..style = PaintingStyle.fill;
paint0Fill.color = Colors.white.withOpacity(1.0);
canvas.drawRect(
Rect.fromLTWH(size.width, size.height, size.width, size.height),
paint0Fill);
Path path1 = Path();
path1.moveTo(size.width * -0.3864734, size.height * 1.198212);
path1.cubicTo(
size.width * -0.3810845,
size.height * 1.186197,
size.width * -0.3785169,
size.height * 1.156080,
size.width * -0.3764010,
size.height * 1.137212);
path1.cubicTo(
size.width * -0.3713961,
size.height * 1.092883,
size.width * -0.3669493,
size.height * 1.051270,
size.width * -0.3575386,
size.height * 1.014241);
path1.cubicTo(
size.width * -0.3243696,
size.height * 0.8837810,
size.width * -0.2729783,
size.height * 0.8435839,
size.width * -0.2219942,
size.height * 0.8634234);
path1.cubicTo(
size.width * -0.1570452,
size.height * 0.8887518,
size.width * -0.1022331,
size.height * 1.020577,
size.width * -0.03565870,
size.height * 1.009788);
path1.cubicTo(
size.width * -0.01412295,
size.height * 1.006299,
size.width * 0.007669348,
size.height * 0.9878832,
size.width * 0.02492778,
size.height * 0.9463942);
path1.cubicTo(
size.width * 0.04539420,
size.height * 0.8972190,
size.width * 0.05555242,
size.height * 0.8167664,
size.width * 0.05369179,
size.height * 0.7357372);
path1.cubicTo(
size.width * 0.05157464,
size.height * 0.6434606,
size.width * 0.02728019,
size.height * 0.5706350,
size.width * 0.01675833,
size.height * 0.4866949);
path1.cubicTo(
size.width * 0.005145797,
size.height * 0.3940314,
size.width * 0.005209928,
size.height * 0.2857299,
size.width * 0.01851198,
size.height * 0.1954569);
path1.cubicTo(
size.width * 0.03363188,
size.height * 0.09277737,
size.width * 0.07097174,
size.height * 0.02641387,
size.width * 0.1067075,
size.height * 0.006575905);
path1.cubicTo(
size.width * 0.1450097,
size.height * -0.01468372,
size.width * 0.1896635,
size.height * 0.01568715,
size.width * 0.2187486,
size.height * 0.09652555);
path1.cubicTo(
size.width * 0.2634879,
size.height * 0.2207876,
size.width * 0.2402843,
size.height * 0.4017854,
size.width * 0.2633599,
size.height * 0.5523474);
path1.cubicTo(
size.width * 0.2829710,
size.height * 0.6802934,
size.width * 0.3317729,
size.height * 0.7264956,
size.width * 0.3755072,
size.height * 0.7098241);
path1.cubicTo(
size.width * 0.4228140,
size.height * 0.6917956,
size.width * 0.4620145,
size.height * 0.6216839,
size.width * 0.4959324,
size.height * 0.5174533);
path1.cubicTo(
size.width * 0.5271981,
size.height * 0.4213650,
size.width * 0.5538865,
size.height * 0.3093803,
size.width * 0.5891304,
size.height * 0.2271847);
path1.cubicTo(
size.width * 0.6203768,
size.height * 0.1542949,
size.width * 0.6558768,
size.height * 0.1001438,
size.width * 0.6932802,
size.height * 0.06951467);
path1.cubicTo(
size.width * 0.7760870,
size.height * 0.001793934,
size.width * 0.8752754,
size.height * 0.04857803,
size.width * 0.9447802,
size.height * 0.2130336);
path1.cubicTo(
size.width * 1.009171,
size.height * 0.3654051,
size.width * 1.050063,
size.height * 0.6072088,
size.width * 1.068242,
size.height * 0.8540511);
path1.cubicTo(
size.width * 1.070572,
size.height * 0.8856496,
size.width * 1.087787,
size.height * 1.264190,
size.width * 1.079981,
size.height * 1.264190);
path1.cubicTo(
size.width * 1.079297,
size.height * 1.264190,
size.width * 1.082720,
size.height * 1.277372,
size.width * 1.082034,
size.height * 1.277372);
path1.lineTo(size.width * -0.3864734, size.height * 1.198212);
path1.close();
Paint paint1Fill = Paint()..style = PaintingStyle.fill;
paint1Fill.color = (color != null)
? color!.withOpacity(0.3)
: ApplicationTheme.lightPurple.withOpacity(0.3);
canvas.drawPath(path1, paint1Fill);
Path path2 = Path();
path2.moveTo(size.width * -0.03414227, size.height * 1.352044);
path2.cubicTo(
size.width * -0.02382215,
size.height * 1.327372,
size.width * 0.01664838,
size.height * 1.326920,
size.width * 0.02961256,
size.height * 1.312942);
path2.cubicTo(
size.width * 0.05436812,
size.height * 1.286197,
size.width * 0.07703406,
size.height * 1.241292,
size.width * 0.09454010,
size.height * 1.181891);
path2.cubicTo(
size.width * 0.1356075,
size.height * 1.042599,
size.width * 0.1564184,
size.height * 0.7964745,
size.width * 0.2281051,
size.height * 0.7736058);
path2.cubicTo(
size.width * 0.2921377,
size.height * 0.7531825,
size.width * 0.3362101,
size.height * 0.9187007,
size.width * 0.3946981,
size.height * 0.9616715);
path2.cubicTo(
size.width * 0.5159396,
size.height * 1.050781,
size.width * 0.6185242,
size.height * 0.8287591,
size.width * 0.7163092,
size.height * 0.6414620);
path2.cubicTo(
size.width * 0.8354589,
size.height * 0.4131905,
size.width * 0.9737150,
size.height * 0.2811117,
size.width * 1.104254,
size.height * 0.5236861);
path2.cubicTo(
size.width * 1.200717,
size.height * 0.7029912,
size.width * 1.217391,
size.height * 1.003358,
size.width * 1.217391,
size.height * 1.323504);
path2.lineTo(size.width * 0.05788647, size.height * 1.330204);
path2.cubicTo(
size.width * 0.04775821,
size.height * 1.330204,
size.width * 0.03319469,
size.height * 1.344635,
size.width * 0.02338635,
size.height * 1.350307);
path2.cubicTo(
size.width * 0.01266104,
size.height * 1.356489,
size.width * 0.002724614,
size.height * 1.363774,
size.width * -0.008149952,
size.height * 1.363708);
path2.cubicTo(
size.width * -0.01787304,
size.height * 1.363642,
size.width * -0.02736159,
size.height * 1.368409,
size.width * -0.03623188,
size.height * 1.359781);
path2.cubicTo(
size.width * -0.03582681,
size.height * 1.356942,
size.width * -0.03512319,
size.height * 1.354365,
size.width * -0.03414227,
size.height * 1.352044);
path2.close();
Paint paint2Fill = Paint()..style = PaintingStyle.fill;
paint2Fill.color = Colors.white.withOpacity(0.05);
canvas.drawPath(path2, paint2Fill);
}