Remove error from onPairingStateChange (#75)

* Remove error from onPairingStateChange

* Update ChangeLog and Readme

* Update Changelog
This commit is contained in:
Rohit Sangwan
2024-08-13 19:49:21 +05:30
committed by GitHub
parent 40819d5796
commit f7c05b2490
8 changed files with 17 additions and 19 deletions
+1
View File
@@ -1,5 +1,6 @@
## 0.12.0
* BREAKING CHANGE: `unPair` is now `unpair`
* BREAKING CHANGE: `onPairingStateChange` does not return error anymore
* Add `pair()`, `isPaired` and `onPairingStateChange` support for Apple and web
* `connect()` and `pair()` now return a bool result
* Add `PlatformConfig` property in `StartScan`
+1 -1
View File
@@ -203,7 +203,7 @@ bool? isPaired = await UniversalBle.pair(deviceId); // Returns true if successfu
UniversalBle.pair(deviceId, pairingCommand: BleCommand(service:"SERVICE", characteristic:"ENCRYPTED_CHARACTERISTIC",));
// Receive pairing state changes
UniversalBle.onPairingStateChange = (String deviceId, bool isPaired, String? error) {
UniversalBle.onPairingStateChange = (String deviceId, bool isPaired) {
// Handle pairing state change
}
+2 -2
View File
@@ -103,13 +103,13 @@ class MockUniversalBle extends UniversalBlePlatform {
@override
Future<bool> pair(String deviceId) async {
updatePairingState(deviceId, true, null);
updatePairingState(deviceId, true);
return true;
}
@override
Future<void> unpair(String deviceId) async {
updatePairingState(deviceId, false, null);
updatePairingState(deviceId, false);
}
@override
@@ -81,14 +81,9 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
_addLog("Value", data);
}
void _handlePairingStateChange(
String deviceId, bool isPaired, String? error) {
void _handlePairingStateChange(String deviceId, bool isPaired) {
print('isPaired $deviceId, $isPaired');
if (error != null && error.isNotEmpty) {
_addLog("PairingStateChangeError", "(Paired: $isPaired): $error ");
} else {
_addLog("PairingStateChange - isPaired", isPaired);
}
_addLog("PairingStateChange - isPaired", isPaired);
}
Future<void> _discoverServices() async {
+2 -2
View File
@@ -325,7 +325,7 @@ class UniversalBle {
bool commandResult =
await _executeBleCommand(deviceId, services, bleCommand);
if (updateCallbackValue) {
_platform.updatePairingState(deviceId, commandResult, null);
_platform.updatePairingState(deviceId, commandResult);
}
return commandResult;
}
@@ -334,7 +334,7 @@ class UniversalBle {
"FailedToPerform EncryptedCharOperation: $e",
);
if (updateCallbackValue) {
_platform.updatePairingState(deviceId, false, e.toString());
_platform.updatePairingState(deviceId, false);
}
return false;
}
@@ -281,7 +281,7 @@ class UniversalBleLinux extends UniversalBlePlatform {
await device.pair();
return true;
} catch (error) {
updatePairingState(deviceId, false, error.toString());
updatePairingState(deviceId, false);
return false;
}
}
@@ -448,7 +448,7 @@ class UniversalBleLinux extends UniversalBlePlatform {
updateScanResult(device.toBleDevice());
break;
case BluezProperty.paired:
updatePairingState(device.address, device.paired, null);
updatePairingState(device.address, device.paired);
break;
// Ignored these properties updates
case BluezProperty.bonded:
@@ -190,7 +190,7 @@ class _UniversalBleCallbackHandler extends UniversalBleCallbackChannel {
@override
void onPairStateChange(String deviceId, bool isPaired, String? error) =>
pairStateChange(deviceId, isPaired, error);
pairStateChange(deviceId, isPaired);
}
extension _UniversalBleScanResultExtension on UniversalBleScanResult {
@@ -6,6 +6,7 @@ import 'package:universal_ble/universal_ble.dart';
abstract class UniversalBlePlatform {
ScanFilter? _scanFilter;
StreamController? _connectionStreamController;
final Map<String, bool> _pairStateMap = {};
Future<AvailabilityState> getBluetoothAvailabilityState();
@@ -93,8 +94,10 @@ abstract class UniversalBlePlatform {
onAvailabilityChange?.call(state);
}
void updatePairingState(String deviceId, bool isPaired, String? error) {
onPairingStateChange?.call(deviceId, isPaired, error);
void updatePairingState(String deviceId, bool isPaired) {
if (_pairStateMap[deviceId] == isPaired) return;
_pairStateMap[deviceId] = isPaired;
onPairingStateChange?.call(deviceId, isPaired);
}
// Do not use these directly to push updates
@@ -135,7 +138,6 @@ typedef OnScanResult = void Function(BleDevice scanResult);
typedef OnAvailabilityChange = void Function(AvailabilityState state);
typedef OnPairingStateChange = void Function(
String deviceId, bool isPaired, String? error);
typedef OnPairingStateChange = void Function(String deviceId, bool isPaired);
typedef OnQueueUpdate = void Function(String id, int remainingQueueItems);