paintForPainter method Null safety

void paintForPainter(
  1. Canvas canvas,
  2. Size size,
  3. {required bool pressed,
  4. required bool pressedFromKeyboard,
  5. required bool showAccelerators}
)

Implementation

void paintForPainter(final Canvas canvas, final Size size,
    {required final bool pressed,
    required final bool pressedFromKeyboard,
    required final bool showAccelerators}) {
  final double h = height;
  final double w = width;
  assert((size.height / h - size.width / w) / w < 0.0000001);
  canvas.scale(size.height / h);

  // Draw  gold text
  TextSpan span = TextSpan(style: bFactory.fTextStyle, text: fText);
  TextPainter tp = TextPainter(
      text: span,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr);
  tp.layout(minWidth: w);
  tp.paint(canvas, bFactory.fTextOffset);

  final Paint p = bFactory.fill;

  // Draw borders
  // That's 1 for all but the enter key
  p.color = Colors.black;
  canvas.drawRRect(outerBorder, p);
  if (pressed) {
    canvas.save();
    canvas.translate(0, innerBorder.bottom);
    canvas.scale(1.0, outerBorderPressedScale);
    canvas.translate(0, -innerBorder.bottom);
  }
  p.color = innerBorderColor;
  canvas.drawRRect(innerBorder, p);

  // draw lower surface
  if (pressed) {
    canvas.translate(0, innerBorder.bottom);
    canvas.scale(1.0, 1.11 / outerBorderPressedScale);
    canvas.translate(0, -innerBorder.bottom);
    p.color = lowerSurfaceColorPressed;
  } else {
    p.color = lowerSurfaceColor;
  }
  canvas.drawRRect(lowerSurface, p);

  // draw blue text
  drawBlueText(canvas, w);
  span = TextSpan(style: bFactory.gTextStyle, text: gText);

  // draw upper surface
  if (pressed) {
    canvas.translate(0, upperSurface.bottom);
    canvas.scale(1.0, 1.0 / 1.11);
    canvas.translate(0, -upperSurface.bottom);
    p.color = upperSurfaceColorPressed;
  } else {
    p.color = upperSurfaceColor;
  }
  canvas.drawRRect(upperSurface, p);
  drawWhiteText(canvas, keyTextStyle, uText, w);

  if (pressed) {
    if (pressedFromKeyboard) {
      Paint p = Paint()
        ..color = Color(0xff00ef00)
        ..style = PaintingStyle.stroke
        ..strokeWidth = 2;
      canvas.drawRRect(outerBorder, p);
    }
    canvas.restore();
  }
  if (showAccelerators) {
    drawKeyboardAccelerator(canvas);
  }
}