classic_bluetooth_flutter 1.0.0
classic_bluetooth_flutter: ^1.0.0 copied to clipboard
A Flutter plugin that provides Bluetooth Classic functionality for both Android and iOS platforms, supporting device discovery, connection, and data transfer.
Classic Bluetooth Flutter #
A Flutter plugin for Bluetooth Classic communication supporting both Android and iOS platforms.
Features #
- Bluetooth device discovery
- Connect to Bluetooth devices
- Send and receive data
- Monitor Bluetooth state changes
- Support for both Android and iOS
Getting Started #
Add this to your package's pubspec.yaml
file:
dependencies:
classic_bluetooth_flutter: ^1.0.0
Usage #
// Initialize Bluetooth
final bluetooth = FlutterBluetoothClassic();
// Check if Bluetooth is enabled
bool enabled = await bluetooth.isBluetoothEnabled();
// Start discovery
await bluetooth.startDiscovery();
// Connect to a device
await bluetooth.connect(deviceAddress);
// Send data
await bluetooth.sendString('Hello World');
// Listen for received data
bluetooth.onDataReceived.listen((data) {
print('Received: ${data.asString()}');
});
Permissions #
Android #
Add these permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
iOS #
Add these keys to your Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need Bluetooth access for communication</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need Bluetooth access for communication</string>
Example #
Check the example
folder for a complete working example.
License #
This project is licensed under the MIT License - see the LICENSE file for details.