bluetooth_rfcomm 0.1.1 copy "bluetooth_rfcomm: ^0.1.1" to clipboard
bluetooth_rfcomm: ^0.1.1 copied to clipboard

Cross-platform Bluetooth Classic RFCOMM serial for Dart and Flutter — one package for CLI and Flutter on Windows, macOS, Linux, Android and iOS.

example/example.dart

// Minimal `bluetooth_rfcomm` usage: connect to the first paired device and do a
// round-trip over the RFCOMM serial channel. For a fuller CLI (list / scan /
// connect / doctor), see `bin/btc.dart` and this directory's README.
//
// ignore_for_file: avoid_print
import 'dart:typed_data';

import 'package:bluetooth_rfcomm/bluetooth_rfcomm.dart';

Future<void> main() async {
  final bt = BluetoothRfcomm.instance;

  if (!await bt.isSupported()) {
    print('Bluetooth Classic is not available on this host.');
    return;
  }

  // Paired devices — instant and radio-silent (no inquiry).
  final paired = await bt.bondedDevices();
  if (paired.isEmpty) {
    print('No paired devices. Pair one in your OS settings first.');
    return;
  }

  final device = paired.first;
  print('Connecting to ${device.name ?? device.id.address}…');

  // Open the RFCOMM channel. The SPP channel is resolved via SDP unless you pass
  // an explicit `channel:`. (macOS requires a real, non-zero channel.)
  final conn = await bt.connect(device);

  conn.input.listen(
    (Uint8List bytes) => print('rx ${bytes.length} bytes'),
    onDone: () => print('disconnected'),
  );

  conn.add(Uint8List.fromList('AT\r\n'.codeUnits)); // non-blocking send
  await conn.finish(); // flush, then close
}
0
likes
160
points
352
downloads

Documentation

Documentation
API reference

Publisher

verified publishercarson.lol

Weekly Downloads

Cross-platform Bluetooth Classic RFCOMM serial for Dart and Flutter — one package for CLI and Flutter on Windows, macOS, Linux, Android and iOS.

Homepage
Repository (GitHub)
View/report issues

Topics

#bluetooth #serial #rfcomm #ffi #flutter

License

BSD-3-Clause (license)

Dependencies

code_assets, dbus, ffi, hooks, logging, meta, native_toolchain_c

More

Packages that depend on bluetooth_rfcomm