搜索插件、代码仓与 APP 分类

插件详情v2.3.0

flutter_thermal_printer

用于通过 ESC/POS 命令在热敏打印机上打印的 Flutter 插件。

AndroidiOSmacOSWindows
近 30 天下载
9900
喜欢数
143
Pub 分数
140

安装插件

flutter pub add flutter_thermal_printer

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,通过 ESC/POS 命令实现向热敏打印机打印。它支持 Android、iOS、macOS 和 Windows,使开发者能够直接向兼容的热敏打印机发送格式化文本、条形码和图像。该包提供了一个简单的 API 来发出 ESC/POS 命令,非常适合零售、酒店业和销售点应用中的收据打印。它可无缝集成到 Flutter 应用中,并通过平台通道利用原生平台功能。

适合场景

  • POS系统中的收据打印
  • 库存标签打印
  • 事件票务生成
  • 订单确认打印
  • 基于移动设备的自助打印

主要特点

  • 支持 ESC/POS 命令集
  • 跨平台兼容性
  • 文本、条形码和图像打印
  • ESC/POS 命令的简单 API
  • 通过平台通道的原生集成

适合对象

  • 零售和餐饮POS应用
  • 移动打印解决方案
  • 库存管理工具
  • 活动和票务应用
  • 自助服务终端和自助服务应用

使用建议

  • 需要兼容的热敏打印机
  • ESC/POS 命令知识,用于高级格式化
  • 仅限支持蓝牙或USB打印的设备
  • 可能需要特定于平台的设置
  • 打印机驱动程序的可用性因操作系统而异

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_thermal_printer

Buy Me A Coffee

If you find this project helpful and want to support its development, you can buy me a coffee:

Buy Me A Coffee

Getting Started

This plugin is used to print data on thermal printers with ease across multiple platforms.

🎉 New Feature: USB Printing Services

✨ Exciting Update! We now support USB printing services across multiple platforms! Connect your thermal printers directly via USB for faster, more reliable printing without the need for wireless connections.

Supported Platforms for USB:

  • 🤖 Android - Full USB support
  • 🖥️ Windows - Complete USB integration
  • 🍎 macOS - Native USB connectivity

Experience enhanced printing performance with direct USB connections!

Currently Supported

Service Android iOS macOS Windows
Bluetooth ✅ ✅ ✅ ✅
USB ✅ ✅ ✅
BLE ✅ ✅ ✅ ✅
WiFi ✅ ✅ ✅ ✅
final _flutterThermalPrinterPlugin = FlutterThermalPrinter.instance;

// Enum ConnectionType
enum ConnectionType {
  BLE,
  USB,
  NETWORK,
}

// Additional Functions
// Recommended Function for getting printers
getPrinters(
  refreshDuration: Duration,
  connectionTypes: List<ConnectionType>,
) {
  // Supports WINDOWS, ANDROID , Macos for USB
  // MAC, IOS, ANDROID, WINDOWS for BLUETOOTH.
}

// Refer to Example for Complete code 

macOS printer connection types

Installed macOS print queues are classified using their native device URI: usb:// is USB; dnssd://, ipp://, ipps://, http://, https://, socket://, lpd://, and smb:// are NETWORK. Unknown or missing schemes have a null connectionType and display as UNKNOWN.

await FlutterThermalPrinter.instance.getPrinters(
  connectionTypes: [ConnectionType.USB, ConnectionType.BLE, ConnectionType.NETWORK],
);

The default scan includes all three types. An explicit USB-only scan excludes network queues; a NETWORK-only scan returns installed network queues on macOS. Unknown system queues appear when both USB and NETWORK are requested. This does not discover uninstalled LAN printers or identify thermal/ESC/POS compatibility.

Printer.deviceUri preserves the destination URI and Printer.queueName holds the macOS queue ID. System queues continue printing through the native macOS backend, including printWidget; a Bonjour/IPPS URI is not passed to the raw TCP network printer API. The queue's isConnected value still indicates that it is installed, not that the physical printer is reachable. Other platforms retain their existing discovery mechanisms.

Bluetooth Services

Feature Android iOS macOS Windows
Start scanning ✅ ✅ ✅ ✅
Stop scanning ✅ ✅ ✅ ✅
Connect printer ✅ ✅ ✅ ✅
Disconnect printer ✅ ✅ ✅ ✅
Print data ✅ ✅ ✅ ✅
Print widget ✅ ✅ ✅ ✅

USB Services

Feature Android iOS macOS Windows
Start scanning ✅ ✅ ✅
Stop scanning ✅ ✅ ✅
Connect printer ✅ ✅ ✅
Print data ✅ ✅ ✅
Print widget ✅ ✅ ✅

WiFi Services

Feature Android iOS macOS Windows
Connect printer ✅ ✅ ✅ ✅
Disconnect printer ✅ ✅ ✅ ✅
Print data ✅ ✅ ✅ ✅
Print widget ✅ ✅ ✅ ✅

Printer Model Class

String? address;
String? name;
ConnectionType? connectionType;
bool? isConnected;
String? vendorId;
String? productId;

Additional Features

Screenshot to Printer

Easily capture and print widgets as images using the printWidget method.

Image Cropping for Long Prints

Handles long data by cropping images and printing them in chunks to ensure seamless printing on devices with limited buffer capacity.

Connection Type Validation
  • Ensures ConnectionType compatibility and alerts when unsupported combinations are used.
BLE State Monitoring

Provides real-time monitoring for Bluetooth states, ensuring proactive error handling and reconnections.

BLE Connection Configuration

Customize BLE connection behavior to optimize for different printer models:

// Global configuration (applies to all BLE connections)
FlutterThermalPrinter.instance.bleConfig =
    BleConfig(connectionStabilizationDelay: Duration(seconds: 3));

// Per-connection override for specific devices
await FlutterThermalPrinter.instance.connect(
  printer,
  connectionStabilizationDelay: Duration(seconds: 2),
);

// Default behavior (10 seconds) - no configuration needed
await FlutterThermalPrinter.instance.connect(printer);
Configuration Use Case
Global config Set once for consistent behavior across all connections
Per-call override Fine-tune for specific printer models that connect faster/slower
Default (10s) Backwards compatible, works with most printers

Notes and Recommendations

  • Windows & MacOS Users: Make sure you have the XPrinter driver installed on Windows for printer compatibility.
    Download the driver from XPrinter Driver.

  • Cross-Platform Usage: Ensure Bluetooth permissions and configurations are set correctly for Android and iOS.


Contributing Guidelines

We welcome contributions to enhance the plugin's functionality!
To contribute, please fork the repository, make changes, and submit a pull request.
For bug reports or feature requests, feel free to open an issue.


Contributors

Contributors

Feel free to contribute to this project and help make it better for everyone!


所属分类

依赖

依赖清单 7 项

源码仓库

使用此插件的项目

暂无相关数据。