paint method

  1. @override
void paint(
  1. PaintingContext context,
  2. Offset offset
)
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 PaintingContext.paintChild on the given context.

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.

Implementation

@override
void paint(PaintingContext context, Offset offset) {
  final canvas = context.canvas;
  canvas.save();
  canvas.translate(offset.dx, offset.dy);

  final center = size.center(Offset.zero);
  final r = size.shortestSide / 2;

  // Clip to circle
  canvas
      .clipPath(Path()..addOval(Rect.fromCircle(center: center, radius: r)));

  // Roll rotation
  final roll = _rollController.value * math.pi / 180;
  canvas.save();
  canvas.translate(center.dx, center.dy);
  canvas.rotate(roll);
  canvas.translate(-center.dx, -center.dy);

  // Pitch offset (1.5px per degree)
  final pitchOffset = _pitchController.value * 1.5;

  // Sky
  canvas.drawRect(
    Rect.fromLTWH(0, 0, size.width, center.dy + pitchOffset),
    Paint()..color = _tokens.skyColor,
  );

  // Ground
  canvas.drawRect(
    Rect.fromLTWH(0, center.dy + pitchOffset, size.width,
        size.height - center.dy - pitchOffset),
    Paint()..color = _tokens.groundColor,
  );

  // Horizon line
  canvas.drawLine(
    Offset(0, center.dy + pitchOffset),
    Offset(size.width, center.dy + pitchOffset),
    Paint()
      ..color = _tokens.horizonLineColor
      ..strokeWidth = _tokens.horizonLineWidth,
  );

  // Pitch ladder (every 10 degrees)
  _paintPitchLadder(canvas, center, pitchOffset);

  canvas.restore();

  // Aircraft symbol (fixed, no rotation)
  _paintAircraftSymbol(canvas, center);

  // Roll arc
  _paintRollArc(canvas, center, r);

  canvas.restore();
}