render method

  1. @override
void render(
  1. Canvas canvas
)
override

Implementation

@override
void render(Canvas canvas) {
  if (followerTarget == null || !show) {
    return;
  }
  double yPosition = (y - height) - margin;

  double xPosition = (followerTarget!.width - width) / 2 + x;

  if (drawPosition == BarLifePorition.bottom) {
    yPosition = followerTarget!.bottom + (followerOffset?.y ?? 0.0) + margin;
  }

  yPosition = yPosition;

  double currentBarLife = (_life * width) / _maxLife;

  if (borderWidth > 0) {
    final RRect borderRect = borderRadius.toRRect(Rect.fromLTWH(
      xPosition,
      yPosition,
      width,
      height,
    ));

    canvas.drawRRect(
      borderRect,
      _barLiveBorderPaint,
    );
  }

  final RRect bgRect = borderRadius.toRRect(Rect.fromLTWH(
    xPosition,
    yPosition,
    width,
    height,
  ));

  canvas.drawRRect(
    bgRect,
    _barLiveBgPaint,
  );

  final RRect lifeRect = borderRadius.toRRect(Rect.fromLTWH(
    xPosition,
    yPosition,
    currentBarLife,
    height,
  ));

  canvas.drawRRect(
    lifeRect,
    _barLivePaint
      ..color = _getColorLife(
        currentBarLife,
        width,
        colors ??
            [
              const Color(0xFFF44336),
              const Color(0xFFFFEB3B),
              const Color(0xFF4CAF50),
            ],
      ),
  );

  if (showLifeText) {
    double xText = _textOffset.x + xPosition + (width - _textSize.x) / 2;
    double yText = _textOffset.y + yPosition + (height - _textSize.y) / 2;
    _textConfig.render(
      canvas,
      _getLifeText(),
      Vector2(xText, yText),
    );
  }

  super.render(canvas);
}