搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.5

thermal_printer

一個 Flutter 插件,可在不同平台(如 Android、iOS、Windows)以及不同介面(藍牙和 BLE、TCP 和 USB)上向印表機傳送 ESC 命令

AndroidiOSWindows
近 30 天下載
436
喜歡數
38
Pub 分數
110

安裝套件

flutter pub add thermal_printer

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

thermal_printer 套件是一個 Flutter 插件,可於多個平台(包括 Android、iOS 與 Windows)向熱敏印表機傳送 ESC/POS 指令。它支援多種連接方式,例如藍牙、BLE、TCP 與 USB,非常適合在各種環境中列印收據、標籤與發票。此套件透過抽象底層通訊協定,簡化了與硬體印表機的整合。對於銷售點系統、庫存管理與行動列印應用尤其有用。

適用情境

  • POS系統中的收據列印
  • 庫存標籤列印
  • 透過藍牙進行移動列印
  • 隨時隨地產生發票
  • 跨平台列印解決方案

主要特色

  • 支援 Android、iOS 和 Windows
  • 多重連接介面:藍牙、BLE、TCP、USB
  • 直接發送 ESC/POS 命令
  • 與 Flutter 應用輕鬆整合
  • 跨平台相容性

適合對象

  • 零售與酒店應用
  • 庫存和物流軟體
  • 移動銷售點系統
  • 客製印刷解決方案
  • 開發跨平台列印功能的開發者

使用建議

  • 需要相容的熱敏列印機
  • 需要印表機特定的 ESC/POS 命令知識
  • Android/iOS 上需要藍牙權限
  • USB 連接可能需要額外的設定
  • 網路列印機所需的TCP/IP設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

thermal_printer

Pub Version

A library to discover printers, and send printer commands.

This library allows to print esc commands to printers in different platforms such as android, ios, windows and different interfaces as Bluetooth and BLE, USB and Wifi/Ethernet

Inspired by flutter_pos_printer.

Main Features

  • Android, iOS and Windows support
  • Scan for bluetooth devices
  • Send raw List<int> bytes data to a device, review this library to generate ESC/POS commands flutter_esc_pos_utils.

Features

Android iOS Windows Description
USB interface :white_check_mark: :white_square_button: :white_check_mark: Allows connection with usb devices.
Bluetooth classic interface :white_check_mark: :white_square_button: :white_square_button: Allows connection with classic bt devices.
Bluetooth low energy (BLE) interface :white_check_mark: :white_check_mark: :white_square_button: Allows connection with bt BLE devices.
Net (ethernet/wifi) interface :white_check_mark: :white_check_mark: :white_check_mark: Allows connection with network devices.
scan :white_check_mark: :white_check_mark: :white_check_mark: Starts a scan for only Bluetooth devices or network devices(Android/iOS).
connect :white_check_mark: :white_check_mark: :white_check_mark: Establishes a connection to the device.
disconnect :white_check_mark: :white_check_mark: :white_check_mark: Cancels an active or pending connection to the device.
state :white_check_mark: :white_check_mark: :white_check_mark: Stream of state changes for the Bluetooth Device.
print :white_check_mark: :white_check_mark: :white_check_mark: print bytes.

Getting Started

For a full example please check /example folder. Here are only the most important parts of the code to illustrate how to use the library.

Generate bytes to print through flutter_esc_pos_utils.

    import 'package:esc_pos_utils/esc_pos_utils.dart';

    final profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm58, profile);
    List<int> bytes = [];

    bytes += generator.text('Test Print', styles: const PosStyles(align: PosAlign.center));
    bytes += generator.text('Product 1');
    bytes += generator.text('Product 2');

Android

Allow to connect bluetooth (classic and BLE), USB and network devices

Change the minSdkVersion for Android

thermal_printer is compatible only from version 21 of Android SDK so you should change this in android/app/build.gradle:

In build.gradle set

    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 33
        ...

select type of device PrinterType ( bluetooth, usb, network)

if select bluetooth you can send optional params

  • isBle -> allow to connect with bluetooth that supports this technology
  • autoconnect -> allow to reconnect when state of device is None

USB: you can enable the native broadcast receiver to notify connected usb devices put the following code in AndroidManifest

   <receiver
        android:name="com.codingdevs.thermal_printer.usb.UsbReceiver"
        android:exported="false">

        <intent-filter>
            <action android:name="android.hardware.usb.action.ACTION_USB_PERMISSION" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            
        </intent-filter>
    </receiver>

iOS

Allow to connect bluetooth (BLE) and network devices

Windows

Allow to connect USB and network devices To network devices is necessary to set ipAddress

How to use it

init a PrinterManager instance
import 'package:thermal_printer/thermal_printer.dart';

    var printerManager = PrinterManager.instance;

scan
    var devices = [];
    _scan(PrinterType type, {bool isBle = false}) {
        // Find printers
        PrinterManager.instance.discovery(type: type, isBle: isBle).listen((device) {
            devices.add(device);
        });
    }
connect
_connectDevice(PrinterDevice selectedPrinter, PrinterType type, {bool reconnect = false, bool isBle = false, String? ipAddress = null}) async {
    switch (type) {
      // only windows and android
      case PrinterType.usb:
        await PrinterManager.instance.connect(
            type: type,
            model: UsbPrinterInput(name: selectedPrinter.name, productId: selectedPrinter.productId, vendorId: selectedPrinter.vendorId));
        break;
      // only iOS and android
      case PrinterType.bluetooth:
        await PrinterManager.instance.connect(
            type: type,
            model: BluetoothPrinterInput(
                name: selectedPrinter.name,
                address: selectedPrinter.address!,
                isBle: isBle,
                autoConnect: reconnect));
        break;
      case PrinterType.network:
        await PrinterManager.instance.connect(type: type, model: TcpPrinterInput(ipAddress: ipAddress ?? selectedPrinter.address!));
        break;
      default:
    }
  }
disconnect
    _disconnectDevice(PrinterType type) async {
        await PrinterManager.instance.disconnect(type: type);
        }
listen bluetooth state
    PrinterManager.instance.stateBluetooth.listen((status) {
      log(' ----------------- status bt $status ------------------ ');
    });
send bytes to print
    _sendBytesToPrint(List<int> bytes, PrinterType type) async { 
      PrinterManager.instance.send(type: type, bytes: bytes);
    }

Troubleshooting

error:'State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode' info.plist add:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-central</string>
    <string>bluetooth-peripheral</string>
</array>

Credits

  • https://github.com/andrey-ushakov/esc_pos_utils
  • https://github.com/bailabs/esc-pos-printer-flutter
  • https://github.com/feedmepos/flutter_printer/tree/master/packages/flutter_pos_printer

所屬分類

依賴

依賴清單 8 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。