Skip to content

Dart SDK

The Dart SDK supports cross-platform Flutter applications on iOS, Android, Windows, and macOS.

All packages are published on pub.dev. Search for the psdk prefix.

dependencies:
psdk_frame_father: ^latest # Core framework
psdk_device_adapter: ^latest # Device adapter
dependencies:
psdk_fruit_cpcl: ^latest # CPCL Commands
psdk_fruit_esc: ^latest # ESC Commands
psdk_fruit_tspl: ^latest # TSPL Commands
dependencies:
psdk_bluetooth_ble: ^latest # BLE (iOS/Android/macOS)
psdk_bluetooth_classic: ^latest # Bluetooth Classic (Android)
psdk_bluetooth_windows: ^latest # Windows Bluetooth
Package nameDescriptionPlatform
psdk_frame_fatherCore frameworkAll platforms
psdk_device_adapterDevice adapterAll platforms
psdk_bluetooth_bleBLEiOS/Android/macOS
psdk_bluetooth_classicBluetooth ClassicAndroid
psdk_bluetooth_windowsWindows BluetoothWindows
psdk_fruit_cpclCPCL commandsAll platforms
psdk_fruit_escESC commandsAll platforms
psdk_fruit_tsplTSPL commandsAll platforms
psdk_networkWi-Fi connectionAll platforms
psdk_usb_standardUSB connectionAndroid
psdk_usb_windowsUSB connectionWindows
import 'package:psdk_bluetooth_classic/psdk_bluetooth_classic.dart';
// Start Bluetooth scanning
await ClassicBluetooth().startDiscovery(
disconnectConnectedDevice: false
);
// Listen for scan results
ClassicBluetooth().discovered().listen((devices) {
for (final device in devices) {
print('Device found: ${device.name}');
}
});
// Connect to the device
final connectedDevice = await ClassicBluetooth().connect(device);
print('Connected: ${connectedDevice.name}');
await ClassicBluetooth().disconnect();

ESC commands are widely used by thermal receipt printers. See the ESC command reference for details.

import 'package:psdk_fruit_esc/psdk_fruit_esc.dart';
final esc = ESC.generic(connectedDevice);
await esc
.initialize()
.align(Align.center)
.text('收银小票')
.align(Align.left)
.text('商品A x1 ¥29.90')
.cut()
.write();
final esc = ESC.generic(connectedDevice);
await esc
.initialize()
// Title
.align(Align.center)
.textSize(width: 2, height: 2)
.bold(true)
.text('XX 便利店')
.bold(false)
.textSize(width: 1, height: 1)
.text('订单号: 20240115001')
.text('================================')
// Product list
.align(Align.left)
.text('可乐 500ml x2 ¥6.00')
.text('薯片 大包 x1 ¥8.50')
.text('--------------------------------')
// Total
.textSize(width: 1, height: 2)
.text('合计: ¥14.50')
.textSize(width: 1, height: 1)
// QR code
.align(Align.center)
.qrcode('https://shop.example.com', size: 5)
.text('扫码关注店铺')
.feed(3)
.cut()
.write();
import 'dart:ui' as ui;
// Load an image
final image = await loadImage('assets/logo.png');
final esc = ESC.generic(connectedDevice);
await esc
.initialize()
.image(EscImage(image: image))
.feed(3)
.cut()
.write();

CPCL commands are used by portable label printers. See the CPCL command reference for details.

import 'package:psdk_fruit_cpcl/psdk_fruit_cpcl.dart';
final cpcl = CPCL.generic(connectedDevice);
await cpcl
.page(CPCLPage(width: 576, height: 400))
.text(CPCLText(x: 50, y: 50, content: '商品标签'))
.barcode(CPCLBarcode(x: 50, y: 150, content: '1234567890'))
.print()
.write();
final cpcl = CPCL.generic(connectedDevice);
await cpcl
.page(CPCLPage(width: 576, height: 400))
// Title
.center()
.text(CPCLText(
x: 0, y: 30,
font: 4, size: 2,
content: '商品标签',
))
// Product information
.left()
.text(CPCLText(x: 30, y: 100, content: '名称: 有机苹果'))
.text(CPCLText(x: 30, y: 140, content: '规格: 500g/袋'))
.text(CPCLText(x: 30, y: 180, content: '价格: ¥25.90'))
// Barcode
.barcode(CPCLBarcode(
x: 100, y: 230,
type: CPCLBarcodeType.code128,
height: 60,
content: '6901234567890',
))
// QR code
.qrcode(CPCLQRCode(
x: 400, y: 100,
content: 'https://example.com',
))
.print()
.write();

TSPL commands are used by label and barcode printers. See the TSPL command reference for details.

import 'package:psdk_fruit_tspl/psdk_fruit_tspl.dart';
final tspl = TSPL.generic(connectedDevice);
await tspl
.page(TPage().width(60).height(40))
.cls()
.text(TText().x(50).y(50).content('标签内容'))
.print(1)
.write();
final tspl = TSPL.generic(connectedDevice);
await tspl
.page(TPage().width(60).height(40))
.gap(3)
.direction(Direction.up)
.cls()
// Title
.text(TText()
.x(180).y(30)
.font('TSS24.BF2')
.xMulti(2).yMulti(2)
.content('商品标签'))
// Separator line
.bar(TBar().x(30).y(80).width(420).height(2))
// Product information
.text(TText().x(30).y(100).content('品名: 有机苹果'))
.text(TText().x(30).y(140).content('规格: 500g/袋'))
.text(TText().x(30).y(180).content('价格: ¥25.90'))
// Barcode
.barcode(TBarcode()
.x(100).y(220)
.type('128')
.height(60)
.content('6901234567890'))
// QR code
.qrcode(TQRCode()
.x(350).y(100)
.cellWidth(4)
.content('https://example.com'))
.print(1)
.write();
connectedDevice.received.listen((data) {
print('Printer response: $data');
// Parse printer status, Query results, etc.
});
try {
await cpcl.write();
print('Print successful');
} on BluetoothException catch (e) {
print('Bluetooth error: ${e.message}');
} on PrinterException catch (e) {
print('Printer error: ${e.message}');
} catch (e) {
print('Unknown error: $e');
}
import 'package:psdk_bluetooth_ble/psdk_bluetooth_ble.dart';
// Initialize
final ble = BleBluetooth();
// Scan for devices
await ble.startDiscovery();
// Listen for discovered devices
ble.discovered().listen((devices) {
print('Found ${devices.length} devices');
});
// Connect to a device
final connectedDevice = await ble.connect(device);
// Disconnect
await ble.disconnect();

For complete examples, see: