- override
Paint this render object into the given context at the given offset.
Subclasses should override this method to provide a visual appearance for themselves. The render object's local coordinate system is axis-aligned with the coordinate system of the context's canvas and the render object's local origin (i.e, x=0 and y=0) is placed at the given offset in the context's canvas.
Do not call this function directly. If you wish to paint yourself, call
markNeedsPaint
instead to schedule a call to this function. If you wish
to paint one of your children, call one of the paint child functions on
the given context, such as paintChild
or paintChildWithClipRect
.
When painting one of your children (via a paint child function on the given context), the current canvas held by the context might change because draw operations before and after painting children might need to be recorded on separate compositing layers.
Source
@override void paint(PaintingContext context, Offset offset) { assert(size.width != null); assert(size.height != null); _painter ??= _decoration.createBoxPainter(markNeedsPaint); final ImageConfiguration filledConfiguration = configuration.copyWith(size: size); if (position == DecorationPosition.background) { int debugSaveCount; assert(() { debugSaveCount = context.canvas.getSaveCount(); return true; }); _painter.paint(context.canvas, offset, filledConfiguration); assert(() { if (debugSaveCount != context.canvas.getSaveCount()) { throw new FlutterError( '${_decoration.runtimeType} painter had mismatching save and restore calls.\n' 'Before painting the decoration, the canvas save count was $debugSaveCount. ' 'After painting it, the canvas save count was ${context.canvas.getSaveCount()}. ' 'Every call to save() or saveLayer() must be matched by a call to restore().\n' 'The decoration was:\n' '${decoration.toString(" ")}\n' 'The painter was:\n' ' $_painter' ); } return true; }); if (decoration.isComplex) context.setIsComplexHint(); } super.paint(context, offset); if (position == DecorationPosition.foreground) { _painter.paint(context.canvas, offset, filledConfiguration); if (decoration.isComplex) context.setIsComplexHint(); } }