classic_blue 1.1.0 copy "classic_blue: ^1.1.0" to clipboard
classic_blue: ^1.1.0 copied to clipboard

A Flutter Bluetooth transport plugin with Bluetooth Classic on Android and BLE on iOS.

Classic Blue #

A Flutter Bluetooth transport plugin with Bluetooth Classic support on Android and BLE support on iOS.

Features #

  • Check Bluetooth support and state.
  • Discover nearby Bluetooth devices.
  • List paired Android classic devices.
  • Restore already connected BLE peripherals on iOS with known service UUIDs.
  • Connect and disconnect devices through a unified transport API.
  • Send and receive string or byte data.
  • Listen to Bluetooth state, connection, discovery, data, and log streams.

Platform Support #

Platform Transport
Android Bluetooth Classic
iOS BLE

Installation #

Add the package to your pubspec.yaml:

dependencies:
  classic_blue: ^1.1.0

Import it in Dart:

import 'package:classic_blue/classic_blue.dart';

Permissions #

Android #

Add the required permissions to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Android 12+ -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

iOS #

Add Bluetooth usage descriptions to ios/Runner/Info.plist:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app needs Bluetooth access to communicate with devices.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth access to communicate with devices.</string>

Basic Usage #

import 'package:classic_blue/classic_blue.dart';

final classicBlue = ClassicBlue();

Future<void> connectAndSend() async {
  final supported = await classicBlue.isSupported();
  if (!supported) {
    return;
  }

  final enabled = await classicBlue.isEnabled();
  if (!enabled) {
    await classicBlue.enable();
  }

  final devices = await classicBlue.getPairedDevices();
  if (devices.isEmpty) {
    return;
  }

  await classicBlue.connect(devices.first.address);
  await classicBlue.sendString('Hello Bluetooth');

  classicBlue.onDataReceived.listen((data) {
    final message = data.asString();
    print('Received: $message');
  });
}

For iOS BLE devices, the app must provide the target service UUID and the write / notify characteristic UUIDs when connecting. The plugin no longer contains built-in device-specific defaults.

await classicBlue.connect(
  device.address,
  serviceUuid: '49535343-FE7D-4AE5-8FA9-9FAFD205E455',
  writeCharacteristicUuid: '49535343-8841-43F4-A8D4-ECBE34729BB3',
  notifyCharacteristicUuid: '49535343-1E4D-4BD9-BA61-23C647249616',
);

If you want to restore already connected BLE peripherals on iOS after a Flutter reload, query them with the same service UUID from your app side:

final devices = await classicBlue.getConnectedDevices(
  serviceUuids: const ['49535343-FE7D-4AE5-8FA9-9FAFD205E455'],
);

Example #

An example app is available in the example/ directory:

cd example
flutter run

Notes #

  • Android uses Bluetooth Classic transport.
  • iOS uses BLE transport and does not provide general-purpose Bluetooth Classic serial access.
  • On iOS BLE, serviceUuid, writeCharacteristicUuid, and notifyCharacteristicUuid should be owned by the app layer, not hardcoded inside the plugin.
  • Android device discovery may require location permission, depending on the Android version.
1
likes
150
points
30
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter Bluetooth transport plugin with Bluetooth Classic on Android and BLE on iOS.

Homepage

Topics

#bluetooth #bluetooth-classic #communication #serial #connectivity

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on classic_blue

Packages that implement classic_blue