mf_bluetooth_printer

pub package

Print receipts to Bluetooth thermal printers (3-inch and 4-inch) using ESC/POS.

Installation

dependencies:
  mf_bluetooth_printer: ^1.0.5

Then run flutter pub get.

Permissions: Android — BLUETOOTH_SCAN (optional: android:usesPermissionFlags="neverForLocation"), BLUETOOTH_CONNECT; for Android 11 and below add BLUETOOTH, BLUETOOTH_ADMIN, ACCESS_FINE_LOCATION with android:maxSdkVersion="30". iOS — NSBluetoothAlwaysUsageDescription.

Usage

final printer = BluetoothPrinterService();

Scan and connect

await printer.startScan();

printer.scanResults.addListener(() {
  final devices = printer.scanResults.value;
  // show in UI
});

await printer.connectToDevice(scanResult.device);

Reconnect to saved printer

await printer.reconnectToPrinter('AA:BB:CC:DD:EE:FF');
final receipt = ReceiptData(
  companyInfo: CompanyInfo(name: 'My Co', address1: '...', phone: '...', taxNo: '...'),
  salesmanName: 'John',
  routeName: 'Route 1',
  invoiceNumber: 'INV-001',
  dateTime: DateTime.now(),
  customerPhone: '...',
  paymentMethod: 'cash',
  customerName: '...',
  customerAddress: '...',
  customerCode: '...',
  customerTRN: '...',
  items: [
    ReceiptItem(
      productCode: 'P1',
      name: 'Product',
      quantity: 2,
      price: 10.0,
      netTotal: 20.0,
      vatAmount: 1.0,
      total: 21.0,
    ),
  ],
  totalBeforeTax: 20.0,
  taxAmount: 1.0,
  roundOff: 0.0,
  totalAmount: 21.0,
);

await printer.printReceipt(
  receipt,
  printerSize: PrinterSize.threeInch,  // or PrinterSize.fourInch
  design: PrinterDesignSettings(
    enableLogo: true,
    enableGstVat: true,
    custName: true,
    custCode: true,
    custTrn: true,
    logoPath: '/path/to/logo.png',
  ),
  use4InchFullLayout: false,
);

State

  • printer.isConnectedValueNotifier<bool>
  • printer.isPrintingValueNotifier<bool>
  • printer.scanResultsValueNotifier<List<ScanResult>>
  • printer.isScanningValueNotifier<bool>
  • printer.savedPrinterMac — current MAC or null

Cleanup

printer.dispose();

License

MIT

Libraries

mf_bluetooth_printer
MF Bluetooth Printer – connect to ESC/POS printers and print receipts.