fillText method

void fillText(
  1. String text,
  2. double x,
  3. double y, {
  4. double? maxWidth,
})

Implementation

void fillText(String text, double x, double y, {double? maxWidth}) {
  addAction((Canvas canvas, Size size) {
    TextPainter textPainter = _getTextPainter(text, fillStyle);
    if (maxWidth != null) {
      // FIXME: should scale down to a smaller font size in order to fit the text in the specified width.
      textPainter.layout(maxWidth: maxWidth);
    } else {
      textPainter.layout();
    }
    // Paint text start with baseline.
    double offsetToBaseline = textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic);
    textPainter.paint(canvas, Offset(x, y - offsetToBaseline) - _getAlignOffset(textPainter.width));
  });
}