Skip to main content

fajfield_print 0.1.1 copy "fajfield_print: ^0.1.1" to clipboard
fajfield_print: ^0.1.1 copied to clipboard

Print labels and receipts on any thermal printer (ESC/POS, TSPL, ZPL), any paper width, offline, from one template. Clear logs and debug previews.

example/main.dart

// dart run example/main.dart 192.168.1.50
import 'dart:io';

import 'package:fajfield_print/fajfield_print.dart';

Future<void> main(List<String> args) async {
  final log = PrintLogger.console(LogLevel.debug); // see every step
  final template = PrintTemplate.receipt(Paper.mm80)
    ..centered('{{shop}}', y: 0, size: 32, bold: true)
    ..line(y: 40)
    ..table(rows: 'items', y: 50, columns: [
      {'title': 'Item', 'field': 'name', 'wrap': true},
      {'title': 'Qty', 'field': 'qty', 'width': 80, 'align': 'R'},
      {'title': 'Amount', 'field': 'amount', 'width': 150, 'align': 'R'},
    ])
    ..line(y: 120)
    ..text('Total {{total}}', x: 0, y: 130, size: 28, bold: true)
    ..barcode('{{bill}}', x: 0, y: 180);
  final data = {
    'shop': 'Fresh Mart', 'total': '310.00', 'bill': 'B-10023',
    'items': [
      {'name': 'Tea powder 250g', 'qty': 2, 'amount': '180.00'},
      {'name': 'Coconut oil 1L', 'qty': 1, 'amount': '130.00'},
    ],
  };

  // 1. No printer needed: dry run + preview PNG with element outlines
  final dry = FajPrinter.dryRun(paper: Paper.mm80, logger: log);
  final job = await dry.print(template, data: data);
  File('preview.png').writeAsBytesSync(job.preview(debug: true));
  print(job.report());

  // 2. Real printer, if an IP was given
  if (args.isNotEmpty) {
    final printer = FajPrinter.network(args.first, paper: Paper.mm80, logger: log);
    print(await printer.diagnose());
    try {
      await printer.print(template, data: data);
    } on PrintException catch (e) {
      print('${e.code.name}: ${e.message}\n→ ${e.hint}');
    }
  } else {
    print('Looking for printers on this network…');
    print(await discoverPrinters(logger: log));
  }
}
1
likes
160
points
208
downloads

Documentation

Documentation
API reference

Publisher

verified publisherfajfield.com

Weekly Downloads

Print labels and receipts on any thermal printer (ESC/POS, TSPL, ZPL), any paper width, offline, from one template. Clear logs and debug previews.

Homepage
Repository (GitHub)
View/report issues

Topics

#printing #thermal-printer #esc-pos #zpl #label

License

MIT (license)

Dependencies

barcode

More

Packages that depend on fajfield_print