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

패키지 상세v4.3.0

bluetooth_print

BluetoothPrint는 iOS 및 Android용 블루투스 열전사 프린터 앱을 개발하는 데 도움이 되는 블루투스 플러그인입니다.

AndroidiOS
30일 다운로드
354
좋아요
276
Pub 점수
140

패키지 설치

flutter pub add bluetooth_print

패키지 개요

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

BluetoothPrint는 Android 및 iOS 플랫폼에서 블루투스 열전사 프린터와 통신할 수 있는 애플리케이션을 개발할 수 있도록 해주는 Flutter 플러그인입니다. 텍스트 및 이미지와 같은 인쇄 명령을 호환 장치에 전송하는 과정을 간소화합니다. 이 플러그인은 저수준의 블루투스 상호작용을 처리하여 영수증 인쇄, 티켓팅 및 포인트 오브 세일 시스템에 원활하게 통합될 수 있게 합니다. 주요 두 가지 모바일 운영 체제를 모두 지원하므로, 신뢰성 있고 이동 중에도 사용 가능한 인쇄 기능이 필요한 기업을 위한 크로스플랫폼 솔루션을 제공합니다.

사용 사례

  • 영수증 인쇄
  • 티켓 생성
  • 포인트 오브 세일 시스템
  • 재고 라벨링
  • 모바일 주문 처리

주요 기능

  • 크로스 플랫폼 지원 (iOS 및 안드로이드)
  • 프린트 데이터 전송을 위한 간단한 API
  • 텍스트 및 이미지 인쇄를 지원합니다
  • 내장형 블루투스 장치 탐색
  • 신뢰할 수 있는 연결 관리

적합한 대상

  • 소매 앱
  • 레스토랑 POS 시스템
  • 이벤트 티켓팅 앱
  • 현장 서비스 도구
  • 모바일 재고 관리

고려 사항

  • 호환되는 블루투스 열식 프린터가 필요합니다
  • 특정 프린터 모델에 한정
  • 일부 장치에 대해 추가 구성이 필요할 수 있습니다
  • 플랫폼별 권한이 필요합니다
  • 하드웨어 신뢰성에 따라 다름

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

pub package

Introduction

BluetoothPrint is a bluetooth plugin for Flutter, a new mobile SDK to help developers build bluetooth thermal printer apps for both iOS and Android.(for example, Gprinter pt-280、pt-380、gp-1324、gp-2120 eg.)

Underway(please suggest)

[ ] print x,y positions
[ ] set paper size
[ ] more print examples

verison

4.0.0(flutter 3.x)
3.0.0(flutter 2.x)
2.0.0(flutter 1.12)
1.2.0(flutter 1.9)

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.
print test message :white_check_mark: :white_check_mark: print device test message.
print text :white_check_mark: :white_check_mark: print custom text, support layout.
print image :white_check_mark: :white_check_mark: print image.
print qrcode :white_check_mark: :white_check_mark: print qrcode,support change size.
print barcode :white_check_mark: :white_check_mark: print barcode

Usage

Example

To use this plugin :
  dependencies:
    flutter:
      sdk: flutter
    bluetooth_print:
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_COARSE_LOCATION"/>  
 <application
IOS

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

	<dict>  
	    <key>NSBluetoothAlwaysUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSBluetoothPeripheralUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationAlwaysUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>

For location permissions on iOS see more at: https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services

init a BluetoothPrint instance
import 'package:bluetooth_print/bluetooth_print.dart';
import 'package:bluetooth_print/bluetooth_print_model.dart';


BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
scan
// begin scan
bluetoothPrint.startScan(timeout: Duration(seconds: 4));

// get devices
StreamBuilder<List<BluetoothDevice>>(
    stream: bluetoothPrint.scanResults,
    initialData: [],
    builder: (c, snapshot) => Column(
      children: snapshot.data.map((d) => ListTile(
        title: Text(d.name??''),
        subtitle: Text(d.address),
        onTap: () async {
          setState(() {
            _device = d;
          });
        },
        trailing: _device!=null && _device.address == d.address?Icon(
          Icons.check,
          color: Colors.green,
        ):null,
      )).toList(),
    ),
  ),
connect
await bluetoothPrint.connect(_device);
disconnect
await bluetoothPrint.disconnect();
listen state
      bluetoothPrint.state.listen((state) {
      print('cur device status: $state');
# bluetooth_print

      switch (state) {
        case BluetoothPrint.CONNECTED:
          setState(() {
            _connected = true;
          });
          break;
        case BluetoothPrint.DISCONNECTED:
          setState(() {
            _connected = false;
          });
          break;
        default:
          break;
      }
    });

A new flutter plugin project.

print (esc command, receipt mode)
    Map<String, dynamic> config = Map();
    List<LineText> list = List();
    list.add(LineText(type: LineText.TYPE_TEXT, content: 'A Title', weight: 1, align: LineText.ALIGN_CENTER,linefeed: 1));
    list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent left', weight: 0, align: LineText.ALIGN_LEFT,linefeed: 1));
    list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent right', align: LineText.ALIGN_RIGHT,linefeed: 1));
    list.add(LineText(linefeed: 1));
    list.add(LineText(type: LineText.TYPE_BARCODE, content: 'A12312112', size:10, align: LineText.ALIGN_CENTER, linefeed: 1));
    list.add(LineText(linefeed: 1));
    list.add(LineText(type: LineText.TYPE_QRCODE, content: 'qrcode i', size:10, align: LineText.ALIGN_CENTER, linefeed: 1));
    list.add(LineText(linefeed: 1));
## Getting Started

    ByteData data = await rootBundle.load("assets/images/guide3.png");
    List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    String base64Image = base64Encode(imageBytes);
    list.add(LineText(type: LineText.TYPE_IMAGE, content: base64Image, align: LineText.ALIGN_CENTER, linefeed: 1));
This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

    await bluetoothPrint.printReceipt(config, list);

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

print (tsc command, label mode)
    Map<String, dynamic> config = Map();
    config['width'] = 40; // 标签宽度,单位mm
    config['height'] = 70; // 标签高度,单位mm
    config['gap'] = 2; // 标签间隔,单位mm

    // x、y坐标位置,单位dpi,1mm=8dpi
    List<LineText> list = List();
    list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:10, content: 'A Title'));
    list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:40, content: 'this is content'));
    list.add(LineText(type: LineText.TYPE_QRCODE, x:10, y:70, content: 'qrcode i\n'));
    list.add(LineText(type: LineText.TYPE_BARCODE, x:10, y:190, content: 'qrcode i\n'));

    List<LineText> list1 = List();
    ByteData data = await rootBundle.load("assets/images/guide3.png");
    List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    String base64Image = base64Encode(imageBytes);
    list1.add(LineText(type: LineText.TYPE_IMAGE, x:10, y:10, content: base64Image,));

    await bluetoothPrint.printLabel(config, list);
    await bluetoothPrint.printLabel(config, list1);

Troubleshooting

ios import third party library

[Please Read link: https://stackoverflow.com/questions/19189463/cocoapods-podspec-issue)
*.podspec add:

# .a filename must begin with lib, eg. 'libXXX.a'
s.vendored_libraries = '**/*.a'
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>

FAQ Support

you can join this QQ group, feedback your problem

Thanks For

카테고리

의존성

의존성 목록 2 개

소스 저장소

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

아직 데이터가 없습니다.