printLabel method

Future<PrintResult> printLabel(
  1. LabelJob label, {
  2. String printerName = '',
  3. TargetPrinter? printer,
  4. String? html,
  5. int copies = 1,
})

A native label; when it cannot be drawn and html is given, the HTML is printed instead (superprinter_flutter's fallback).

Implementation

Future<PrintResult> printLabel(
  LabelJob label, {
  String printerName = '',
  TargetPrinter? printer,
  String? html,
  int copies = 1,
}) async {
  final invalid = label.validate();
  if (invalid != null) return PrintResult.failed(FailReason.unsupported, invalid);
  final r = await _run(
    printer,
    printerName,
    sp.PrintJob(type: sp.JobTypes.label, label: sp.LabelJob.parse(label.encode()), copies: copies),
  );
  if (r.status == JobStatus.printed || html == null || html.isEmpty) return r;
  return printHtml(html, printerName: printerName, printer: printer, copies: copies);
}