### Create Itemized Receipt with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt This example demonstrates how to generate a sales receipt with a columnar layout for items, quantities, prices, and totals. It utilizes the `row` method of PrintBuilder to define column widths and aligns the content within each column. It also includes subtotal, tax, and grand total calculations displayed on the right. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) ..text('SALES RECEIPT', align: AlignPos.center, fontSize: FontSize.big, bold: true) ..text('Receipt #: 2025010201', bold: true) ..text('Date: ${DateTime.now().toString().substring(0, 19)}') ..text('Cashier: Jane Smith') ..line() // Table header with column widths totaling 100% ..row(['Item', 'Qty', 'Price', 'Total'], [40, 15, 20, 25]) ..line(char: '-') // Item rows ..row(['Coffee Latte', '2', '$4.50', '$9.00'], [40, 15, 20, 25]) ..row(['Croissant', '1', '$3.25', '$3.25'], [40, 15, 20, 25]) ..row(['Orange Juice', '1', '$2.50', '$2.50'], [40, 15, 20, 25]) ..line() // Totals ..text('Subtotal: $14.75', align: AlignPos.right) ..text('Tax (8%): $1.18', align: AlignPos.right) ..text('TOTAL: $15.93', align: AlignPos.right, bold: true, fontSize: FontSize.big) ..line(char: '=') ..text('Thank you!', align: AlignPos.center) ..feed(3) ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` -------------------------------- ### Complete Receipt Generation with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt A comprehensive example of generating a full receipt, including headers, item details in a table format, totals, a QR code, and a barcode. It utilizes various text formatting options, row creation for tables, and specific commands for QR and barcodes. Requires a connected thermal printer. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/commands/esc_pos_commands.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) // Header ..text('ACME RETAIL STORE', align: AlignPos.center, fontSize: FontSize.big, bold: true) ..text('123 Commerce Street', align: AlignPos.center) ..text('New York, NY 10001', align: AlignPos.center) ..text('Tel: (555) 123-4567', align: AlignPos.center) ..feed(1) ..line(char: '=') // Receipt info ..text('Receipt #: 2025010201', bold: true) ..text('Date: ${DateTime.now().toString().substring(0, 19)}') ..text('Cashier: John Doe') ..text('Customer: Jane Smith') ..line() // Items table ..row(['Item', 'Qty', 'Price', 'Total'], [40, 15, 20, 25]) ..line(char: '-') ..row(['Coffee Premium', '2', '$4.50', '$9.00'], [40, 15, 20, 25]) ..row(['Croissant', '1', '$3.25', '$3.25'], [40, 15, 20, 25]) ..row(['Orange Juice', '1', '$2.50', '$2.50'], [40, 15, 20, 25]) ..line() // Totals ..text('Subtotal: $14.75', align: AlignPos.right) ..text('Tax (8.5%): $1.25', align: AlignPos.right) ..text('Discount: -$1.00', align: AlignPos.right) ..line(char: '-') ..text('TOTAL: $15.00', align: AlignPos.right, bold: true, fontSize: FontSize.big) ..text('Cash: $20.00', align: AlignPos.right) ..text('Change: $5.00', align: AlignPos.right, bold: true) ..line(char: '=') // QR code for digital receipt ..feed(1) ..text('Digital Receipt:', align: AlignPos.center, bold: true) ..qrCode('https://acmestore.com/receipts/2025010201', size: QRSize.size4) // Tracking barcode ..feed(1) ..text('Tracking:', align: AlignPos.center, bold: true) ..barcode128('2025010201', height: 80) // Footer ..feed(1) ..text('Thank you for shopping!', align: AlignPos.center, bold: true) ..text('Return policy: 30 days', align: AlignPos.center, fontSize: FontSize.compressed) ..text('Visit us at acmestore.com', align: AlignPos.center, fontSize: FontSize.compressed) ..feed(3) ..cut(partial: false); // Full cut (or partial: true for partial cut) bool success = await FlutterThermalPrinterPlus.print(builder); if (!success) { print('Print failed - check printer connection'); } ``` -------------------------------- ### Create and Print a Receipt with Flutter Thermal Printer Plus Source: https://github.com/safwankayakkool/flutter-thermal-printer-plus/blob/main/README.md This code example illustrates how to create a thermal printer receipt using the `PrintBuilder` class and print it. It supports different paper sizes and allows for text formatting like alignment. The `print` function sends the generated commands to the connected printer. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; Future printReceipt() async { // Create a print builder for 80mm paper size final builder = PrintBuilder(PaperSize.mm80) ..text('Hello World!', align: AlignPos.center) ..line() ..text('This is a sample receipt.') ..line() ..cut(); // Print the receipt await FlutterThermalPrinter.print(builder); print('Receipt printed successfully.'); } ``` -------------------------------- ### Get USB Devices - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Retrieves a list of available USB thermal printers connected to the Android device. This function is specific to Android. It returns a list of `PrinterInfo` objects, each containing details about the connected USB printer. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/models/printer_info.dart'; // Get USB devices (Android only) List usbDevices = await FlutterThermalPrinterPlus.getUsbDevices(); for (var device in usbDevices) { print('USB Device: ${device.name}'); } ``` -------------------------------- ### Text Formatting with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Demonstrates various text formatting options including different font sizes, alignment (left, center, right), and styles (bold, underline) using the PrintBuilder. It also shows how to add lines and control spacing. Assumes a configured thermal printer instance. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) // Font sizes ..text('Normal Size Text', fontSize: FontSize.normal) ..text('Big Size Text', fontSize: FontSize.big) ..text('Double Width', fontSize: FontSize.doubleWidth) ..text('Double Height', fontSize: FontSize.doubleHeight) ..text('Compressed Text for More Characters', fontSize: FontSize.compressed) ..feed(1) // Alignment ..text('Left Aligned Text', align: AlignPos.left) ..text('Center Aligned Text', align: AlignPos.center) ..text('Right Aligned Text', align: AlignPos.right) ..feed(1) // Styling ..text('Bold Text', bold: true) ..text('Underlined Text', underline: true) ..text('Bold and Underlined', bold: true, underline: true) ..feed(1) // Combined formatting ..text( 'IMPORTANT NOTICE', align: AlignPos.center, fontSize: FontSize.big, bold: true, underline: true, ) // Lines and spacing ..line(char: '=') // Line with equals signs ..line(char: '-') // Line with dashes ..line() // Default dash line ..feed(2) // Feed 2 blank lines ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` -------------------------------- ### Create Advanced Table with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt This snippet demonstrates creating a table with advanced features like custom column alignment (left, right, center) and multi-line text wrapping. It allows precise control over column widths and how text is displayed within cells, including specific columns that should wrap text. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) ..text('INVENTORY REPORT', align: AlignPos.center, fontSize: FontSize.big, bold: true) ..feed(1) ..line() // Custom alignment per column: left, right, center ..row( ['Product', 'Stock', 'Status'], [50, 25, 25], aligns: [ColumnAlign.left, ColumnAlign.right, ColumnAlign.center], fontSize: FontSize.normal, ) ..line() ..row( ['Coffee Beans Premium', '150', 'OK'], [50, 25, 25], aligns: [ColumnAlign.left, ColumnAlign.right, ColumnAlign.center], ) ..row( ['Paper Cups Large', '25', 'LOW'], [50, 25, 25], aligns: [ColumnAlign.left, ColumnAlign.right, ColumnAlign.center], ) ..row( ['Sugar Packets', '500', 'OK'], [50, 25, 25], aligns: [ColumnAlign.left, ColumnAlign.right, ColumnAlign.center], ) // Multi-line product names with wrapping control ..feed(1) ..text('DETAILED ITEMS:', bold: true) ..row( ['Premium Coffee Beans\nOrganic Fair Trade\n100% Arabica', '2', '$15.99', '$31.98'], [45, 15, 20, 20], aligns: [ColumnAlign.left, ColumnAlign.center, ColumnAlign.right, ColumnAlign.right], wrapColumns: [true, false, false, false], // Only first column wraps lineSpacing: 0, ) ..feed(2) ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` -------------------------------- ### Create Basic Receipt with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt This snippet shows how to create a simple formatted receipt using the PrintBuilder class for an 80mm paper size. It includes basic text formatting like centering, bolding, font size, and line separators. The generated receipt is then printed using FlutterThermalPrinterPlus.print(). ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; // Create a receipt for 80mm paper final builder = PrintBuilder(PaperSize.mm80) ..text( 'MY STORE', align: AlignPos.center, fontSize: FontSize.big, bold: true, ) ..text('123 Main Street', align: AlignPos.center) ..text('Tel: 555-1234', align: AlignPos.center) ..feed(1) ..line(char: '=') ..text('Receipt #: 001234', bold: true) ..text('Date: 2025-01-02 10:30:00') ..line() ..text('Thank you for your purchase!', align: AlignPos.center) ..feed(3) ..cut(); // Print the receipt bool success = await FlutterThermalPrinterPlus.print(builder); if (success) { print('Receipt printed successfully'); } else { print('Print failed'); } ``` -------------------------------- ### Scan and Connect to Bluetooth Thermal Printers in Flutter Source: https://github.com/safwankayakkool/flutter-thermal-printer-plus/blob/main/README.md This snippet demonstrates how to scan for available Bluetooth thermal printers and establish a connection. It requires the `flutter_thermal_printer_plus` package. The function returns a list of discovered printers and connects to a specified printer's address. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; Future connectToPrinter() async { // Scan for Bluetooth printers final printers = await FlutterThermalPrinterPlus.scanBluetoothDevices(); if (printers.isNotEmpty) { // Connect to the first found printer await FlutterThermalPrinterPlus.connectBluetooth(printers.first.address); print('Connected to ${printers.first.name}'); } else { print('No Bluetooth printers found.'); } } ``` -------------------------------- ### Connect to Bluetooth Printer - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Establishes a Bluetooth connection to a thermal printer using its MAC address. After a successful connection, you can verify the connection status. Remember to disconnect when finished to release resources. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; // Connect using printer MAC address String printerAddress = '00:11:22:33:44:55'; bool success = await FlutterThermalPrinterPlus.connectBluetooth(printerAddress); if (success) { print('Connected to printer'); // Check connection status bool isConnected = await FlutterThermalPrinterPlus.isConnected(); print('Connection status: $isConnected'); } else { print('Connection failed'); } // Disconnect when done await FlutterThermalPrinterPlus.disconnectBluetooth(); ``` -------------------------------- ### Print Images with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Prints images directly from byte data, with automatic resizing and conversion to monochrome. This method requires loading image data into a Uint8List and then passing it to the `imageFromBytes` method of `PrintBuilder`. Dependencies include `dart:typed_data` and Flutter services for asset loading. ```dart import 'dart:typed_data'; import 'package:flutter/services.dart'; import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; // Load image from assets ByteData imageData = await rootBundle.load('assets/logo.png'); Uint8List imageBytes = imageData.buffer.asUint8List(); final builder = PrintBuilder(PaperSize.mm80) ..text('STORE LOGO', align: AlignPos.center, bold: true) ..feed(1) // Print image with automatic sizing ..imageFromBytes( imageBytes, align: AlignPos.center, maxWidth: 384, // Maximum width in pixels (optional) ) ..feed(1) ..text('Welcome to our store!', align: AlignPos.center) ..feed(2) ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` -------------------------------- ### Print QR Codes with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Generates and prints QR codes with customizable size and error correction levels. Requires importing necessary modules from the flutter_thermal_printer_plus package. The output is a QR code embedded within a print job. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/commands/esc_pos_commands.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) ..text('ORDER CONFIRMATION', align: AlignPos.center, bold: true) ..text('Order #: ORD-2025-001', align: AlignPos.center) ..feed(1) ..line() ..text('Scan for details:', align: AlignPos.center) // QR code with URL or data ..qrCode( 'https://mystore.com/orders/ORD-2025-001', align: AlignPos.center, size: QRSize.size4, // size1 to size8 correction: QRCorrection.M, // L, M, Q, H (increasing error correction) ) ..feed(1) ..text('https://mystore.com', align: AlignPos.center, fontSize: FontSize.compressed) ..feed(3) ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` -------------------------------- ### Managing Scanner State with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Provides methods to check the current scanning status, stop Bluetooth scanning, stop Wi-Fi scanning, and halt all scanning operations. This is useful for controlling device discovery and ensuring resources are released when scanning is no longer needed. Returns boolean indicating success. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; // Check if currently scanning bool isScanning = await FlutterThermalPrinterPlus.isScanning(); print('Scanning status: $isScanning'); // Stop Bluetooth scanning bool stoppedBluetooth = await FlutterThermalPrinterPlus.stopBluetoothScan(); // Stop WiFi scanning bool stoppedWifi = await FlutterThermalPrinterPlus.stopWifiScan(); // Stop all scanning operations at once bool stoppedAll = await FlutterThermalPrinterPlus.stopAllScanning(); if (stoppedAll) { print('All scanning operations stopped'); } ``` -------------------------------- ### Connect to USB Printer - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Establishes a USB connection to a thermal printer on Android devices using the printer's device name. This method facilitates direct connection for printing via USB. Ensure the device name is correct and the printer is properly connected. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; // Connect to USB printer using device name String deviceName = 'USB_PRINTER_001'; bool success = await FlutterThermalPrinterPlus.connectUsb(deviceName); if (success) { print('Connected to USB printer'); } else { print('USB connection failed'); } ``` -------------------------------- ### Configure Paper Size with PrintBuilder in Dart Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Selects appropriate paper sizes (58mm, 80mm, 110mm) and configures the PrintBuilder with automatic character width calculation for thermal receipt printing. This code snippet is essential for setting up different receipt formats based on the printer's capabilities, impacting line length and readability. ```dart import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; // Available paper sizes // PaperSize.mm58 - 384 dots width, 32 characters normal, 42 compressed // PaperSize.mm72 - 512 dots width, 42 characters normal, 56 compressed // PaperSize.mm80 - 576 dots width, 48 characters normal, 64 compressed // PaperSize.mm110 - 832 dots width, 69 characters normal, 92 compressed // 58mm receipt (compact, mobile printers) final builder58 = PrintBuilder(PaperSize.mm58) ..text('Small receipt format') ..text('Max 32 chars per line'); // 80mm receipt (standard retail) final builder80 = PrintBuilder(PaperSize.mm80) ..text('Standard retail receipt format') ..text('Max 48 characters per line for better readability'); // 110mm receipt (wide format) final builder110 = PrintBuilder(PaperSize.mm110) ..text('Wide format receipt with more space for detailed information') ..text('Maximum 69 characters per line allows for complex tables'); ``` -------------------------------- ### Scan for Bluetooth Printers - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Scans for available Bluetooth thermal printers within range. Requires Bluetooth, Bluetooth Connect, and Location permissions. Returns a list of discovered printers with their names and addresses. Ensure to stop scanning when no longer needed. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/models/printer_info.dart'; import 'package:permission_handler/permission_handler.dart'; // Request Bluetooth permissions first Map statuses = await [ Permission.bluetoothScan, Permission.bluetoothConnect, Permission.location, ].request(); // Scan for Bluetooth printers List printers = await FlutterThermalPrinterPlus.scanBluetoothDevices(); for (var printer in printers) { print('Found: ${printer.name} (${printer.address})'); } // Stop scanning when done await FlutterThermalPrinterPlus.stopBluetoothScan(); ``` -------------------------------- ### Scan for WiFi Printers - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Discovers thermal printers available on the local network. This function scans the network to find printers and returns a list of `PrinterInfo` objects containing their names and IP addresses. Ensure to stop the WiFi scan once the devices are found. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/models/printer_info.dart'; // Scan for WiFi printers on the network List wifiPrinters = await FlutterThermalPrinterPlus.scanWifiPrinters(); for (var printer in wifiPrinters) { print('WiFi Printer: ${printer.name} at ${printer.address}'); } // Stop WiFi scanning await FlutterThermalPrinterPlus.stopWifiScan(); ``` -------------------------------- ### Connect to WiFi Printer - Flutter Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Connects to a network thermal printer using its IP address and port. The default ESC/POS port is typically 9100. This method establishes a connection for sending print jobs over the network. Remember to disconnect after use. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; // Connect to WiFi printer (default ESC/POS port is 9100) String printerIP = '192.168.1.100'; int port = 9100; bool success = await FlutterThermalPrinterPlus.connectWifi(printerIP, port); if (success) { print('Connected to WiFi printer'); } else { print('WiFi connection failed'); } // Disconnect when done await FlutterThermalPrinterPlus.disconnectWifi(); ``` -------------------------------- ### Print Barcodes with Flutter Thermal Printer Plus Source: https://context7.com/safwankayakkool/flutter-thermal-printer-plus/llms.txt Prints various barcode formats like Code128, Code39, and EAN13, including human-readable text. This functionality requires importing specific command classes and models from the flutter_thermal_printer_plus package. The output is a series of barcodes with configurable options. ```dart import 'package:flutter_thermal_printer_plus/flutter_thermal_printer_plus.dart'; import 'package:flutter_thermal_printer_plus/commands/print_builder.dart'; import 'package:flutter_thermal_printer_plus/commands/esc_pos_commands.dart'; import 'package:flutter_thermal_printer_plus/models/paper_size.dart'; final builder = PrintBuilder(PaperSize.mm80) ..text('PRODUCT LABELS', align: AlignPos.center, fontSize: FontSize.big, bold: true) ..feed(1) // Code 128 barcode ..text('Code 128:', align: AlignPos.center, bold: true) ..barcode128( 'PROD12345', align: AlignPos.center, height: 100, // Height in dots (default: 162) width: 2, // Width multiplier 2-6 (default: 2) hriPosition: HRIPosition.below, // none, above, below, both hriFont: HRIFont.fontA, // fontA or fontB ) ..feed(2) // Code 39 barcode ..text('Code 39:', align: AlignPos.center, bold: true) ..barcode39( 'SKU789', align: AlignPos.center, height: 100, width: 2, hriPosition: HRIPosition.below, ) ..feed(2) // EAN13 barcode (requires exactly 12 digits) ..text('EAN13:', align: AlignPos.center, bold: true) ..barcodeEAN13( '123456789012', align: AlignPos.center, height: 100, width: 2, hriPosition: HRIPosition.below, ) ..feed(3) ..cut(); await FlutterThermalPrinterPlus.print(builder); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.