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);

  drawGoldText(canvas, w);

  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);

  drawBlueText(canvas, w);

  // 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 = const Color(0xff00ef00)
        ..style = PaintingStyle.stroke
        ..strokeWidth = 2;
      canvas.drawRRect(outerBorder, p);
    }
    canvas.restore();
  }
  if (showAccelerators) {
    drawKeyboardAccelerator(canvas);
  }
}