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

GitHub 저장소amoLink/bluetooth_print_plus

bluetooth_print_plus

Android 및 iOS를 지원하는 블루투스 열전사 프린터용 플러터 플러그인

bluetooth_print_plus 프로젝트 이미지
스타
11
포크
26
최근 푸시(UTC)
2025. 3. 22.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

Bluetooth Print Plus

pub package GitHub stars GitHub forks qq_group tg_group

Introduction

Bluetooth Print Plus is a Bluetooth plugin used to print thermal printers in Flutter, a new mobile SDK to help developers build bluetooth thermal printer apps for iOS and Android.

Important, important, important. First, you need to run the demo to confirm the printer command type ! ! ! now support tspl/tsc、cpcl、esc pos. If this plugin is helpful to you, please give it a like, Thanks.

Buy Me A Coffee/请我喝杯咖啡

Plan

Version plan
1.1.x blue and tsc command, esc print image command
1.5.x support cpcl command
2.x.x improve esc command
3.x.x support zpl command

Features

Android iOS Description
scan :white_check_mark: :white_check_mark: Starts a scan for Bluetooth Low Energy devices.
connect :white_check_mark: :white_check_mark: Establishes a connection to the device.
disconnect :white_check_mark: :white_check_mark: Cancels an active or pending connection to the device.
state :white_check_mark: :white_check_mark: Stream of state changes for the Bluetooth Device.

Usage

Example

To use this plugin :
dependencies:
  flutter:
    sdk: flutter
  bluetooth_print_plus: ^2.4.5
Add permissions for Bluetooth

We need to add the permission to use Bluetooth and access location:

Android

In the android/app/src/main/AndroidManifest.xml let’s add:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
IOS

In the ios/Runner/Info.plist let’s add:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need BLE permission</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need BLE permission</string>
import
import 'package:bluetooth_print_plus/bluetooth_print_plus.dart';
BluetoothPrintPlus useful property
BluetoothPrintPlus.isBlueOn;
BluetoothPrintPlus.isScanning;
BluetoothPrintPlus.isConnected;
listen

late StreamSubscription<bool> _isScanningSubscription;
late StreamSubscription<BlueState> _blueStateSubscription;
late StreamSubscription<ConnectState> _connectStateSubscription;
late StreamSubscription<Uint8List> _receivedDataSubscription;
late StreamSubscription<List<BluetoothDevice>> _scanResultsSubscription;
late List<BluetoothDevice> _scanResults;
  • scan results
/// listen scanResults
_scanResultsSubscription = BluetoothPrintPlus.scanResults.listen((event) {
  if (mounted) {
    setState(() {
      _scanResults = event;
    });
  }
});
  • state
/// listen isScanning
_isScanningSubscription = BluetoothPrintPlus.isScanning.listen((event) {
  print('********** isScanning: $event **********');
  if (mounted) {
    setState(() {});
  }
});

/// listen blue state
_blueStateSubscription = BluetoothPrintPlus.blueState.listen((event) {
  print('********** blueState change: $event **********');
  /// blue state changed, do something...
});

/// listen connect state
_blueStateSubscription = _BluetoothPrintPlus.connectState.listen((event) {
  print('********** connectState change: $event **********');
  /// connect state changed, do something...
});
  • received Data
_BluetoothPrintPlus.receivedData.listen((data) {
  print('********** received data: $data **********');
  /// received data, do something...
});
scan

// begin scan
await BluetoothPrintPlus.startScan(timeout: Duration(seconds: 10));

// get devices
_scanResultsSubscription = BluetoothPrintPlus.scanResults.listen((event) {
  if (mounted) {
    setState(() {
      _scanResults = event;
    });
  }
});
connect

await BluetoothPrintPlus.connect(_device);
disconnect

await BluetoothPrintPlus.disconnect();
print/write

final ByteData bytes = await rootBundle.load("assets/dithered-image.png");

/// write tsc command, for example:
final Uint8List image = bytes.buffer.asUint8List();
await tscCommand.cleanCommand();
await tscCommand.size(width: 76, height: 130);
await tscCommand.cls(); // most after size
await tscCommand.image(image: image, x: 50, y: 60);
await tscCommand.print(1);
final cmd = await tscCommand.getCommand();
if (cmd == null) return;
BluetoothPrintPlus.write(cmd);

/// write cpcl command, for example:
await cpclCommand.cleanCommand();
await cpclCommand.size(width: 76 * 8, height: 76 * 8);
await cpclCommand.image(image: image, x: 10, y: 10);
await cpclCommand.print();
final cmd = await cpclCommand.getCommand();
if (cmd == null) return;
BluetoothPrintPlus.write(cmd);

/// write esc command, for example:
await escCommand.cleanCommand();
await escCommand.print();
await escCommand.image(image: image);
await escCommand.print();
final cmd = await escCommand.getCommand();
if (cmd == null) return;
BluetoothPrintPlus.write(cmd);
Cancel Subscription
@override
void dispose() {
  super.dispose();
  _isScanningSubscription.cancel();
  _blueStateSubscription.cancel();
  _connectStateSubscription.cancel();
  _receivedDataSubscription.cancel();
  _scanResultsSubscription.cancel();
  _scanResults.clear();
  _device = null;
}

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>

Stargazers over time

Stargazers over time

amoLink GitHub avatar
GitHub 작성자

amoLink ↗

Xiamen, China
언어JavaDartObjective-CCMakeC++RubySwiftHTMLC

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 3 개

  • flutter{"sdk":"flutter"}
  • rxdart^0.28.0
  • flutter_test개발 의존성{"sdk":"flutter"}

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗