thermal_printer_flutter 0.0.1+6 copy "thermal_printer_flutter: ^0.0.1+6" to clipboard
thermal_printer_flutter: ^0.0.1+6 copied to clipboard

A Flutter plugin for thermal printing supporting Bluetooth, USB, and Network printers across Android, iOS, macOS, Windows, Linux, and Web platforms. Easy to use and integrates with esc_pos_utils for g [...]

THERMAL PRINTER FLUTTER #

Flutter plugin for thermal printing with support for multiple platforms and connection types.

Support #

Platform USB Bluetooth Network
Android
iOS
macOS
Windows
Linux
Web 🚧

Project Setup #

Android #

  1. Add the following permissions to the android/app/src/main/AndroidManifest.xml file:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  1. For Android 12 or higher, also add:
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

iOS #

  1. Add the following keys to the ios/Runner/Info.plist file:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>We need Bluetooth access to connect to thermal printers</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>We need Bluetooth access to connect to thermal printers</string>
  1. For iOS 13 or higher, also add:
<key>NSBluetoothAlwaysAndWhenInUseUsageDescription</key>
<string>We need Bluetooth access to connect to thermal printers</string>

macOS #

  1. Add the following keys to the macos/Runner/Info.plist file:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>We need Bluetooth access to connect to thermal printers</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>We need Bluetooth access to connect to thermal printers</string>
  1. Add the following keys to the macos/Runner/DebugProfile.entitlements file:
<key>com.apple.security.device.bluetooth</key>
<true/>
  1. Add the following keys to the macos/Runner/Release.entitlements file:
<key>com.apple.security.device.bluetooth</key>
<true/>

Windows #

  1. For USB printers, ensure the printer drivers are installed.
  2. For Bluetooth printers, Windows must support Bluetooth LE (Bluetooth 4.0 or higher).

Linux #

  1. For network printers, ensure that the firewall allows connections on port 9100 (or the configured port).

Web #

  1. For network printers, ensure that the web server allows WebSocket connections.
  2. Add the following script to the web/index.html file:
<script>
  if ("serviceWorker" in navigator) {
    window.addEventListener("flutter-first-frame", function () {
      navigator.serviceWorker.register("flutter_service_worker.js");
    });
  }
</script>

Usage #

import 'package:thermal_printer_flutter/thermal_printer_flutter.dart';

// Create an instance of the plugin
final thermalPrinter = ThermalPrinterFlutter();
Printer? _selectedPrinter;

// Only Android, Ios, Macos
final bluetoothPrinters = await thermalPrinter.getPrinters(printerType: PrinterType.bluethoot);
// Only Windows
final usbPrinters = await thermalPrinter.getPrinters(printerType: PrinterType.usb);


// Connect to a printer only bluethoot
final connected = await thermalPrinter.connect(printer: selectedPrinter);


 Future<void> _printTest({required ThermalPrinterFlutter termalPrinter,  required Printer printer}) async {
    try {
      final generator = Generator(PaperSize.mm80, await CapabilityProfile.load());
      List<int> bytes = [];

      bytes += generator.text('Print Test',
          styles: const PosStyles(
            align: PosAlign.center,
            bold: true,
            height: PosTextSize.size2,
            width: PosTextSize.size2,
          ));
      bytes += generator.feed(2);
      bytes += generator.text('Date: ${DateTime.now()}');
      bytes += generator.feed(2);
      bytes += generator.text('This is a test print');
      bytes += generator.feed(2);
      bytes += generator.cut();

      await termalPrinter.printBytes(bytes: bytes, printer: printer);

    } catch (e) {
      print('Error printing: $e');
    }
  }

Dependency Compatibility #

If you are using the packages below, we recommend using these specific versions for better compatibility:

dependencies:
  web: ^0.5.1
  image: ^4.5.4

Example #

Check out the complete example at example/lib/main.dart for a sample implementation with a graphical interface.

Contribution #

Contributions are welcome! Feel free to open issues or submit pull requests.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

8
likes
140
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for thermal printing supporting Bluetooth, USB, and Network printers across Android, iOS, macOS, Windows, Linux, and Web platforms. Easy to use and integrates with esc_pos_utils for generating ESC/POS print commands.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

esc_pos_utils_plus, flutter, flutter_web_plugins, image, plugin_platform_interface, web

More

Packages that depend on thermal_printer_flutter

Packages that implement thermal_printer_flutter