搜索插件、代码仓与 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

源码仓库

使用此插件的项目

暂无相关数据。