FlutterClassicBluetooth class Core
Primary API for Bluetooth Classic operations.
Provides a unified interface across Android, iOS (MFi only), Windows, macOS, and Linux for discovering, pairing, and communicating with Bluetooth Classic devices over RFCOMM.
final bluetooth = FlutterClassicBluetooth();
// Check platform capabilities
final caps = await bluetooth.getPlatformCapabilities();
// Discover devices
if (caps.canDiscoverDevices) {
bluetooth.discoveryResults.listen((device) {
print('Found: ${device.displayName}');
});
await bluetooth.startDiscovery();
}
// Connect and communicate
final connection = await bluetooth.connect(
address: 'AA:BB:CC:DD:EE:FF',
uuid: '00001101-0000-1000-8000-00805F9B34FB',
);
connection.input.listen((data) => print('Received: $data'));
await connection.output.add(Uint8List.fromList([0x01, 0x02]));
await connection.finish();
Constructors
- FlutterClassicBluetooth()
-
Returns the singleton instance of FlutterClassicBluetooth.
factory
Properties
-
adapterState
→ Stream<
BtcAdapterState> -
Stream of adapter state changes.
no setter
-
discoveryResults
→ Stream<
BtcDevice> -
Stream of devices found during discovery.
no setter
-
discoveryState
→ Stream<
bool> -
Stream that emits
truewhen discovery starts andfalsewhen it stops.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bondDevice(
String address) → Future< bool> -
Initiates pairing with the device at
address. -
bondState(
String address) → Stream< BtcBondState> - Stream of bond state changes for a specific device.
-
connect(
{required String address, String uuid = BtcUuid.spp, bool secure = true, Duration? timeout}) → Future< BtcConnection> -
Connects to the device at
addressusing the givenuuid. -
connectWithReconnect(
{required String address, String uuid = BtcUuid.spp, bool secure = true, BtcReconnectPolicy policy = const BtcReconnectPolicy()}) → BtcReconnectingConnection -
Connects to
addressand automatically reconnects if the link drops. -
disableBluetooth(
) → Future< bool> - Requests the system to disable the Bluetooth adapter.
-
disconnect(
int id) → Future< void> -
Disconnects the connection with the given
id. -
enableBluetooth(
) → Future< bool> - Requests the system to enable the Bluetooth adapter.
-
getAdapterAddress(
) → Future< String?> - Returns the local adapter's hardware address (MAC).
-
getAdapterName(
) → Future< String?> - Returns the local adapter's friendly name.
-
getPairedDevices(
) → Future< List< BtcDevice> > - Returns the list of currently paired/bonded devices.
-
getPlatformCapabilities(
) → Future< BtcPlatformCapabilities> - Returns the platform capabilities for Bluetooth Classic.
-
isDiscovering(
) → Future< bool> - Returns whether a discovery scan is currently in progress.
-
isEnabled(
) → Future< bool> - Returns whether the Bluetooth adapter is currently enabled.
-
isSupported(
) → Future< bool> - Returns whether Bluetooth Classic hardware is available on this device.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setDiscoverable(
int durationSeconds) → Future< bool> -
Makes the local device discoverable for
durationSeconds. -
startDiscovery(
) → Future< void> - Starts discovering nearby Bluetooth Classic devices.
-
startServer(
{required String serviceName, String uuid = BtcUuid.spp, bool secure = true}) → Future< BtcServerSocket> -
Creates an RFCOMM server socket listening on the given
uuid. -
stopDiscovery(
) → Future< void> - Stops an ongoing device discovery.
-
toString(
) → String -
A string representation of this object.
inherited
-
unbondDevice(
String address) → Future< bool> -
Removes the bond with the device at
address.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited