$applyPaint method

  1. @override
void $applyPaint(
  1. Canvas canvas
)
override

(Internal usage) Applies the text's paint to the given canvas.

If the text is empty, this method does nothing.

If a backgroundColor is set, this method also draws a colored rectangle that spans the entire intrinsic width and height of the text.

The text is drawn at the top-left corner of the text's bounds, which is affected by the text's transformation matrix and the target space.

If the text's alpha is less than 1.0, the text is drawn with an alpha mask to prevent color bleeding. Otherwise, the text is drawn directly.

Implementation

@override
void $applyPaint(ui.Canvas canvas) {
  super.$applyPaint(canvas);
  if (_text == '') return;
  validate();
  if (backgroundColor != null && backgroundColor!.alpha > 0) {
    canvas.drawRect(
      ui.Rect.fromLTWH(0, 0, intrinsicWidth, textHeight),
      ui.Paint()..color = backgroundColor!,
    );
  }
  if (_paragraph != null) {
    if ($alpha != 1.0) {
//        print("ALPHA is: $alpha");
//        final alphaPaint = PainterUtils.getAlphaPaint($alpha);
//        final alphaPaint = _alphaPaint;
//        var bounds = Rect.fromLTWH(0, 0, textWidth, textHeight);
      canvas.saveLayer(null, _alphaPaint);
      canvas.drawParagraph(_paragraph!, ui.Offset.zero);
      canvas.restore();
    } else {
      canvas.drawParagraph(_paragraph!, ui.Offset.zero);
    }
  }
}