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

套件詳情v1.0.1

flutter_esc_pos_utils

此套件用於產生 ESC/POS 指令,以使用藍牙、WiFi/網路或 USB 掃描機進行列印。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
169
Pub 分數
160

安裝套件

flutter pub add flutter_esc_pos_utils

套件介紹

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

flutter_esc_pos_utils 是一個 Flutter 套件,可產生 ESC/POS 指令,以於藍牙、WiFi/網路或 USB 掃描機上進行列印。它讓開發者能從 Flutter 應用程式向相容的收據列印機傳送格式化列印作業——例如文字、條碼和影像。此套件支援多個平台,包含 Android、iOS、Web、macOS、Windows 和 Linux,非常適合跨平台的銷售點(POS)應用。它透過將底層列印機指令抽象為易於使用的 Dart 方法,簡化了建立可列印內容的流程。

適用情境

  • 銷售點系統
  • 收據列印
  • 標籤列印
  • 庫存管理
  • 事件票務列印
  • 訂單確認列印

主要特色

  • 產生 ESC/POS 指令
  • 支援藍牙、WiFi 和 USB 列印機
  • 跨平台相容性
  • 文字、條碼和圖像列印
  • 易於使用的 API
  • 列印格式選項

適合對象

  • 零售POS應用
  • 移動訂單系統
  • 現場服務報告
  • 餐廳自助點餐機
  • 小型企業軟體

使用建議

  • 需要相容的ESC/POS列印機
  • 印表機特有的小問題可能會影響輸出
  • 對高級印表機功能的支援有限
  • WiFi印表機需要網路設定
  • 移動設備需要藍牙配對

原始 README

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

esc_pos_utils

Base Flutter/Dart classes for ESC/POS printing. Generator class generates ESC/POS commands that can be sent to a thermal printer.

This is the "base" library that used for:

Main Features

  • Connect to Wi-Fi / Ethernet printers
  • Simple text printing using text method
  • Tables printing using row method
  • Text styling:
    • size, align, bold, reverse, underline, different fonts, turn 90°
  • Print images
  • Print barcodes
    • UPC-A, UPC-E, JAN13 (EAN13), JAN8 (EAN8), CODE39, ITF (Interleaved 2 of 5), CODABAR (NW-7), CODE128
  • Paper cut (partial, full)
  • Beeping (with different duration)
  • Paper feed, reverse feed

Note: Your printer may not support some of the presented features (some styles, partial/full paper cutting, reverse feed, barcodes...).

Generate a Ticket

Simple ticket with styles:
List<int> testTicket() {
  final List<int> bytes = [];
  // Using default profile
  final profile = await CapabilityProfile.load();
  final generator = Generator(PaperSize.mm80, profile);
  List<int> bytes = [];

  bytes += generator.text(
      'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
  bytes += generator.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
      styles: PosStyles(codeTable: PosCodeTable.westEur));
  bytes += generator.text('Special 2: blåbærgrød',
      styles: PosStyles(codeTable: PosCodeTable.westEur));

  bytes += generator.text('Bold text', styles: PosStyles(bold: true));
  bytes += generator.text('Reverse text', styles: PosStyles(reverse: true));
  bytes += generator.text('Underlined text',
      styles: PosStyles(underline: true), linesAfter: 1);
  bytes += generator.text('Align left', styles: PosStyles(align: PosAlign.left));
  bytes += generator.text('Align center', styles: PosStyles(align: PosAlign.center));
  bytes += generator.text('Align right',
      styles: PosStyles(align: PosAlign.right), linesAfter: 1);

  bytes += generator.text('Text size 200%',
      styles: PosStyles(
        height: PosTextSize.size2,
        width: PosTextSize.size2,
      ));

  bytes += generator.feed(2);
  bytes += generator.cut();
  return bytes;
}
Print a table row:
generator.row([
    PosColumn(
      text: 'col3',
      width: 3,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col6',
      width: 6,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col3',
      width: 3,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
  ]);
Print an image:

This package implements 3 ESC/POS functions:

  • ESC * - print in column format
  • GS v 0 - print in bit raster format (obsolete)
  • GS ( L - print in bit raster format

Note that your printer may support only some of the above functions.

import 'dart:io';
import 'package:image/image.dart';

final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
// Using `ESC *`
generator.image(image);
// Using `GS v 0` (obsolete)
generator.imageRaster(image);
// Using `GS ( L`
generator.imageRaster(image, imageFn: PosImageFn.graphics);
Print a Barcode:
final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
generator.barcode(Barcode.upcA(barData));
Print a QR Code:

Using native ESC/POS commands:

generator.qrcode('example.com');

To print a QR Code as an image (if your printer doesn't support native commands), add qr_flutter and path_provider as a dependency in your pubspec.yaml file.

String qrData = "google.com";
const double qrSize = 200;
try {
  final uiImg = await QrPainter(
    data: qrData,
    version: QrVersions.auto,
    gapless: false,
  ).toImageData(qrSize);
  final dir = await getTemporaryDirectory();
  final pathName = '${dir.path}/qr_tmp.png';
  final qrFile = File(pathName);
  final imgFile = await qrFile.writeAsBytes(uiImg.buffer.asUint8List());
  final img = decodeImage(imgFile.readAsBytesSync());

  generator.image(img);
} catch (e) {
  print(e);
}

Using Code Tables

Different printers support different sets of code tables. Some printer models are defined in CapabilityProfile class. So, if you want to change the default code table, it's important to choose the right profile:

// Xprinter XP-N160I
final profile = await CapabilityProfile.load('XP-N160I');
final generator = Generator(PaperSize.mm80, profile);
bytes += generator.setGlobalCodeTable('CP1252');

All available profiles can be retrieved by calling :

final profiles = await CapabilityProfile.getAvailableProfiles();

How to Help

  • Add a CapabilityProfile to support your printer's model. A new profile should be added to lib/resources/capabilities.json file
  • Test and report bugs
  • Share your ideas about what could be improved (code optimization, new features...)

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案