A cross-platform (Android/iOS/macOS/Windows/Linux) BluetoothLE plugin for Flutter
- Receive BLE availability changes
- Scan BLE peripheral
- Connect BLE peripheral
- Discover services of BLE peripheral
- Transfer data between BLE central & peripheral
API | Android | iOS | macOS | Windows | Linux |
---|---|---|---|---|---|
availabilityChangeStream | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
isBluetoothAvailable | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
startScan/stopScan | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
connect/disconnect | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
discoverServices | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
setNotifiable | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
readValue | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
writeValue | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
requestMtu | ✔️ | ✔️ | ✔️ | ✔️ |
- Windows' APIs are little different on
discoverServices
: woodemi/quick_blue#76
iOS/macOS
QuickBlue.availabilityChangeStream.listen((state) {
debugPrint('Bluetooth state: ${state.toString()}');
});
Android/iOS/macOS/Windows/Linux
QuickBlue.scanResultStream.listen((result) {
print('onScanResult $result');
});
QuickBlue.startScan();
// ...
QuickBlue.stopScan();
Connect to deviceId
, received from QuickBlue.scanResultStream
QuickBlue.setConnectionHandler(_handleConnectionChange);
void _handleConnectionChange(String deviceId, BlueConnectionState state) {
print('_handleConnectionChange $deviceId, $state');
}
QuickBlue.connect(deviceId);
// ...
QuickBlue.disconnect(deviceId);
Discover services od deviceId
QuickBlue.setServiceHandler(_handleServiceDiscovery);
void _handleServiceDiscovery(String deviceId, String serviceId) {
print('_handleServiceDiscovery $deviceId, $serviceId');
}
QuickBlue.discoverServices(deviceId);
- Pull data from peripheral of
deviceId
Data would receive within value handler of
QuickBlue.setValueHandler
Because it is how peripheral(_:didUpdateValueFor:error:) work on iOS/macOS
// Data would receive from value handler of `QuickBlue.setValueHandler`
QuickBlue.readValue(deviceId, serviceId, characteristicId);
- Send data to peripheral of
deviceId
QuickBlue.writeValue(deviceId, serviceId, characteristicId, value);
- Receive data from peripheral of
deviceId
QuickBlue.setValueHandler(_handleValueChange);
void _handleValueChange(String deviceId, String characteristicId, Uint8List value) {
print('_handleValueChange $deviceId, $characteristicId, ${hex.encode(value)}');
}
QuickBlue.setNotifiable(deviceId, serviceId, characteristicId, true);