strokeText method

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

Implementation

void strokeText(String text, double x, double y, {double? maxWidth}) {
  addAction((Canvas canvas, Size size) {
    TextPainter textPainter = _getTextPainter(text, strokeStyle, shouldStrokeText: true);
    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();
    }

    double offsetToBaseline = textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic);
    // Paint text start with baseline.
    textPainter.paint(canvas, Offset(x, y - offsetToBaseline) - _getAlignOffset(textPainter.width));
  });
}