flutter_tsc_utils 0.1.0
flutter_tsc_utils: ^0.1.0 copied to clipboard
Utilities for generating TSC TSPL/TSPL2 printer commands from Flutter and Dart.
flutter_tsc_utils #
Utilities for generating TSC TSPL / TSPL2 printer commands from Flutter and Dart.
This package is shaped after flutter_esc_pos_utils, but targets TSC label printers and produces TSPL command bytes instead of ESC/POS receipt data.
Features #
- Setup commands like
SIZE,GAP,DENSITY,DIRECTION,REFERENCE, andCLS - Drawing commands like
TEXT,BARCODE,QRCODE,BAR, andBOX - Richer label commands like
BLOCK,PDF417,DMATRIX,REVERSE,ERASE, andPUTBMP - Printer control commands like
SET PEEL,SET TEAR,SET CUTTER,SET PARTIAL_CUTTER,SET REWIND, andSET RIBBON - Bitmap rasterization for the
BITMAPcommand - Flutter-rendered
khmerText()support for Khmer and other Unicode text that printer fonts do not handle well - Input validation for common parameter ranges
- Chainable API plus raw command and raw byte hooks for unsupported TSPL features
Usage #
import 'package:flutter_tsc_utils/flutter_tsc_utils.dart';
Future<void> main() async {
final generator = TscGenerator();
generator
..size(const TscLabelSize(60, 40))
..gap(2, 0)
..density(8)
..direction(TscDirection.forward)
..setPeel(TscToggle.off)
..cls()
..text(20, 20, 'Hello TSC')
..block(
20,
50,
300,
80,
'Multi-line text block',
alignment: TscBlockAlignment.center,
)
..barcode(20, 80, '123456789012')
..qrCode(20, 180, 'https://example.com')
..pdf417(20, 260, 300, 140, 'payload')
..print();
final bytes = generator.build();
// Send bytes over Bluetooth, USB, or TCP to the printer.
}
Khmer Text #
For Khmer, the safest path is rendering text with Flutter and printing it as a bitmap:
import 'package:flutter/painting.dart';
import 'package:flutter_tsc_utils/flutter_tsc_utils.dart';
Future<void> printKhmer() async {
final generator = TscGenerator()
..size(const TscLabelSize(60, 40))
..gap(2, 0)
..cls();
await generator.khmerText(
20,
20,
'សួស្តីពិភពលោក',
options: const TscRenderedTextOptions(
style: TextStyle(
fontSize: 24,
color: Color(0xFF000000),
fontFamily: 'NotoSansKhmer',
),
pixelRatio: 2,
padding: 4,
),
);
generator.print();
}
Notes #
- TSC models vary a bit in supported commands, fonts, and barcode types.
- Layout commands like
SIZEandGAPaccept units, while object placement uses printer dots. khmerText()depends on a Khmer-capable Flutter font such asNotoSansKhmer.- If you need a command that is not wrapped yet, use
rawCommand()orrawBytes().