printText method

Future<PrinterStatus> printText(
  1. Paragraph paragraph, {
  2. Offset offset = Offset.zero,
  3. Color background = const Color(0xFFFFFFFF),
})

Implementation

Future<PrinterStatus> printText(Paragraph paragraph, {Offset offset = Offset.zero, Color background = const Color(0xFFFFFFFF)}) async {
  PictureRecorder recorder = PictureRecorder();
  Canvas c = Canvas(recorder);
  Paint paint = new Paint()..color = background;

  double height =  offset.dy + paragraph.height;

  // TODO Move to constant
  if (height < 100) {
    height = 100;
  }

  c.drawRect(Rect.fromLTWH(0, 0, offset.dx + paragraph.width, height), paint);
  c.drawParagraph(paragraph, offset);
  var picture = await recorder.endRecording().toImage(offset.dx.toInt() + paragraph.width.toInt(), height.toInt());

  return printImage(picture);
}