bluetooth_dart 0.0.1 copy "bluetooth_dart: ^0.0.1" to clipboard
bluetooth_dart: ^0.0.1 copied to clipboard

Cross-platform Bluetooth Low Energy for Dart and Flutter. Pure Dart (no Flutter dependency) with native BLE from Rust (btleplug) via FFI and a pluggable backend registry.

bluetooth_dart #

Cross-platform Bluetooth Low Energy for Dart, wrapping the Rust btleplug library over dart:ffi. Pure Dart, with no Flutter dependency, so it works in CLI tools as well as Flutter apps (via bluetooth_flutter, which builds the native library for you).

Usage #

import 'package:bluetooth_dart/bluetooth_dart.dart';

final bt = Bluetooth.instance;

// Request Bluetooth permission (prompts on macOS/iOS; no-op elsewhere).
if ((await bt.requestPermission()).isUsable) {
  // Scan; the stream emits a device on each discovery/advertisement update.
  final scan = await bt.startScan();
  scan.devices.listen((d) => print('${d.id}  ${d.name}  ${d.rssi} dBm'));
  await Future<void>.delayed(const Duration(seconds: 5));
  await scan.stop();

  // Connect and read a characteristic.
  final p = bt.peripheral(someDeviceId);
  await p.connect();
  final services = await p.discoverServices();
  final value = await p.read('00002a37-0000-1000-8000-00805f9b34fb');
  p.subscribe('00002a37-0000-1000-8000-00805f9b34fb').listen(print);
}

The native library #

bluetooth_dart loads bluetooth_core (the Rust crate) over FFI. It does not build it: build it first, or use bluetooth_flutter which builds it automatically via cargokit. Search order:

  1. NativeLibrary.overridePath (set in Dart), then $BLUETOOTH_CORE_LIB.
  2. The OS loader path / Flutter app bundle.
  3. In-repo developer builds under native/bluetooth_core/target/{release,debug}/.

Build it with:

cargo build --manifest-path native/bluetooth_core/Cargo.toml

Pluggable backends #

The active BluetoothBackend is chosen from a registry by availability and priority. The FFI backend is the default on native platforms; the web currently falls through to an UnsupportedBackend floor (a Web Bluetooth backend is planned). Register your own with Bluetooth.instance.registerBackend(...).

Status #

Host Status
Android Tested
Android Emulator Tested
macOS Tested
iOS Tested
iOS Simulator Tested
Ubuntu 24.04 Tested
Web Tested
Windows 11 Tested

Android, iOS, Ubuntu 24.04, Linux macOS, Web (on Chrome on macOS, on Chrome on Ubuntu 24.04, and on Chrome and Edge on Windows 11), and Windows 11 are tested.

1
likes
150
points
121
downloads

Documentation

API reference

Publisher

verified publishermanymath.com

Weekly Downloads

Cross-platform Bluetooth Low Energy for Dart and Flutter. Pure Dart (no Flutter dependency) with native BLE from Rust (btleplug) via FFI and a pluggable backend registry.

Repository (GitHub)
View/report issues

Topics

#bluetooth #ble #btleplug #ffi

License

MIT (license)

Dependencies

ffi, web

More

Packages that depend on bluetooth_dart