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

套件詳情v0.0.4

bluetooth_classic

一個用於連接藍牙經典設備的Flutter外掛程式,主要設計用於串列通訊。

Android
近 30 天下載
1140
喜歡數
27
Pub 分數
145

安裝套件

flutter pub add bluetooth_classic

套件介紹

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

一個 Flutter 插件,用於連接藍牙經典設備,主要用於串列通訊。它提供了一個簡單的介面,可在 Android 上發現、配對並交換資料與藍牙經典周邊裝置。專為需要可靠、底層資料傳輸的應用程式設計,例如工業感測器、醫療設備或自訂硬體。該插件與 Android 的藍牙 API 無縫整合,為專注於裝置通訊的開發者提供最小的抽象層。

適用情境

  • 連接到舊版藍牙設備
  • 傳輸串列數據
  • 工業傳感器整合
  • 醫療器械通訊
  • 自定義硬體控制

主要特色

  • 僅支援 Android
  • 串列通訊焦點
  • 設備發現和配對
  • 低階數據傳輸
  • 藍牙經典版的簡單API

適合對象

  • Android應用開發者
  • 硬體整合商
  • 具有藍牙經典版的物聯網專案
  • 序列協定實作

使用建議

  • 僅限Android平台
  • 無 iOS 支援
  • 需要藍牙權限
  • 取決於裝置相容性
  • 手動處理連接狀態

原始 README

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

bluetooth_classic

A Flutter plugin to connect to Bluetooth Classic devices, mainly designed to work with serial communication.

Pub Version (including pre-releases) Pub Popularity

Features

  • check that permissions are granted to use the device
  • get already paired devices
  • scan for devices
  • connect & disconnect to a device
  • read from connected device
  • write to connected device

Installation

To install the package, simply run flutter pub add bluetooth_classic

Api Documentation

For a list of functions and their definitions, you can look at the documentation on pub.dev

Basic example

Getting Paired Devices
import 'package:bluetooth_classic/bluetooth_classic.dart';

final _bluetoothClassicPlugin = BluetoothClassic();
await _bluetoothClassicPlugin.initPermissions();
List<Device> _discoveredDevices = await _bluetoothClassicPlugin.getPairedDevices();
Scanning for Devices
import 'package:bluetooth_classic/bluetooth_classic.dart';
import 'package:bluetooth_classic/models/device.dart';

final _bluetoothClassicPlugin = BluetoothClassic();
List<Device> _discoveredDevices = [];
await _bluetoothClassicPlugin.initPermissions();
_bluetoothClassicPlugin.onDeviceDiscovered().listen(
  (event) {
    _discoveredDevices = [..._discoveredDevices, event];
  },
);
await _bluetoothClassicPlugin.startScan();
// when you want to stop scanning
await _bluetoothClassicPlugin.stopScan();

Connecting to a device, reading and sending data to it
import 'package:bluetooth_classic/bluetooth_classic.dart';

final _bluetoothClassicPlugin = BluetoothClassic();
Uint8List _data = Uint8List(0);

await _bluetoothClassicPlugin.initPermissions();
// connect to a device with its MAC address and the application uuid you want to use (in this example, serial)
await _bluetoothClassicPlugin.connect("AA:AA:AA:AA", "00001101-0000-1000-8000-00805f9b34fb");

// NB: I'm not doing error checking or seeing if the device is still connected in this code, check the [example folder](/example/lib/main.dart) for a more thorough demonstration
// send data to device
await _bluetoothClassicPlugin.write("ping");

//
_bluetoothClassicPlugin.onDeviceDataReceived().listen((event) {
  setState(() {
    _data = Uint8List.fromList([..._data, ...event]);
  });
});

// disconnect when done
await _bluetoothClassicPlugin.disconnect();

Example Code

You can find the latest example code in the example folder

所屬分類

依賴

依賴清單 1 項

  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案

暫無相關資料。