quick_blue 0.3.0-dev.0 quick_blue: ^0.3.0-dev.0 copied to clipboard
A new flutter plugin project.
quick_blue #
A cross-platform (Android/iOS/macOS/Windows) BluetoothLE plugin for Flutter
Usage #
- Scan BLE peripheral
- Connect BLE peripheral
- Discover services of BLE peripheral
- Transfer data between BLE central & peripheral
Scan BLE peripheral #
Android/iOS/macOS/Windows
QuickBlue.scanResultStream.listen((result) {
print('onScanResult $result');
});
QuickBlue.startScan();
// ...
QuickBlue.stopScan();
Connect BLE peripheral #
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 of BLE peripheral #
Discover services od deviceId
QuickBlue.setServiceHandler(_handleServiceDiscovery);
void _handleServiceDiscovery(String deviceId, String serviceId) {
print('_handleServiceDiscovery $deviceId, $serviceId');
}
QuickBlue.discoverServices(deviceId);
Transfer data between BLE central & peripheral #
- 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);