패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.5

thermal_printer

Android, iOS, Windows 등 다양한 플랫폼과 블루투스 및 BLE, TCP 및 USB 등의 다양한 인터페이스에서 프린터에 ESC 명령을 전송하는 Flutter 플러그인

AndroidiOSWindows
30일 다운로드
436
좋아요
38
Pub 점수
110

패키지 설치

flutter pub add thermal_printer

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

thermal_printer 패키지는 Android, iOS, Windows 등 여러 플랫폼에서 열식 프린터에 ESC/POS 명령을 전송할 수 있는 Flutter 플러그인입니다. 블루투스, 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.