Add error in connection updates (#89)
* Add error in connection updates * implement windows * Update changelog and Docs * minor fix in connect() * Add default timeout in connect * Document new pair and connect API * Fix Connect and Pair apis to throw proper errors and Improve logging * remove import * Rename PairingException and update Exception doc * Update changelog * Update comments --------- Co-authored-by: Foti Dim <fdimanidis@gmail.com>
This commit is contained in:
@@ -59,8 +59,14 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void _handleConnectionChange(String deviceId, bool isConnected) {
|
||||
print('_handleConnectionChange $deviceId, $isConnected');
|
||||
void _handleConnectionChange(
|
||||
String deviceId,
|
||||
bool isConnected,
|
||||
String? error,
|
||||
) {
|
||||
print(
|
||||
'_handleConnectionChange $deviceId, $isConnected ${error != null ? 'Error: $error' : ''}',
|
||||
);
|
||||
setState(() {
|
||||
if (deviceId == widget.deviceId) {
|
||||
this.isConnected = isConnected;
|
||||
@@ -248,12 +254,12 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
enabled: !isConnected,
|
||||
onPressed: () async {
|
||||
try {
|
||||
bool connected = await UniversalBle.connect(
|
||||
await UniversalBle.connect(
|
||||
widget.deviceId,
|
||||
);
|
||||
_addLog("ConnectionResult", connected);
|
||||
_addLog("ConnectionResult", true);
|
||||
} catch (e) {
|
||||
_addLog('ConnectError', e);
|
||||
_addLog('ConnectError (${e.runtimeType})', e);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -405,14 +411,18 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
PlatformButton(
|
||||
enabled: BleCapabilities.supportsAllPairingKinds,
|
||||
onPressed: () async {
|
||||
bool? pairingResult = await UniversalBle.pair(
|
||||
widget.deviceId,
|
||||
// pairingCommand: BleCommand(
|
||||
// service: "",
|
||||
// characteristic: "",
|
||||
// ),
|
||||
);
|
||||
_addLog("Pairing Result", pairingResult);
|
||||
try {
|
||||
await UniversalBle.pair(
|
||||
widget.deviceId,
|
||||
// pairingCommand: BleCommand(
|
||||
// service: "",
|
||||
// characteristic: "",
|
||||
// ),
|
||||
);
|
||||
_addLog("Pairing Result", true);
|
||||
} catch (e) {
|
||||
_addLog('PairError (${e.runtimeType})', e);
|
||||
}
|
||||
},
|
||||
text: 'Pair',
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user