Add connecting and disconnecting states to BleConnectionState (#54)
* Add connecting and disconnecting state * Replace BleConnectionState with boolean in onConnectionChanged callback * Improve Docs and Changelog * Implement GetConnectionState in Windows * Update CHANGELOG.md Co-authored-by: Foti Dim <foti@navideck.com> * Add code level doc of connectionState getter --------- Co-authored-by: Foti Dim <foti@navideck.com>
This commit is contained in:
@@ -31,12 +31,12 @@ class MockUniversalBle extends UniversalBlePlatform {
|
||||
|
||||
@override
|
||||
Future<void> connect(String deviceId, {Duration? connectionTimeout}) async {
|
||||
onConnectionChange?.call(deviceId, BleConnectionState.connected);
|
||||
onConnectionChange?.call(deviceId, true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> disconnect(String deviceId) async {
|
||||
onConnectionChange?.call(deviceId, BleConnectionState.disconnected);
|
||||
onConnectionChange?.call(deviceId, false);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -105,7 +105,7 @@ class MockUniversalBle extends UniversalBlePlatform {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isConnected(String deviceId) {
|
||||
Future<BleConnectionState> getConnectionState(String deviceId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void _handleConnectionChange(String deviceId, BleConnectionState state) {
|
||||
print('_handleConnectionChange $deviceId, ${state.name}');
|
||||
void _handleConnectionChange(String deviceId, bool isConnected) {
|
||||
print('_handleConnectionChange $deviceId, $isConnected');
|
||||
setState(() {
|
||||
if (deviceId == widget.deviceId) {
|
||||
isConnected = (state == BleConnectionState.connected);
|
||||
this.isConnected = isConnected;
|
||||
}
|
||||
});
|
||||
_addLog('Connection', state.name.toUpperCase());
|
||||
_addLog('Connection', isConnected ? "Connected" : "Disconnected");
|
||||
// Auto Discover Services
|
||||
if (isConnected) {
|
||||
if (this.isConnected) {
|
||||
_discoverServices();
|
||||
}
|
||||
}
|
||||
@@ -347,13 +347,13 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
PlatformButton(
|
||||
onPressed: () async {
|
||||
_addLog(
|
||||
'IsConnected',
|
||||
await UniversalBle.isConnected(
|
||||
'ConnectionState',
|
||||
await UniversalBle.getConnectionState(
|
||||
widget.deviceId,
|
||||
),
|
||||
);
|
||||
},
|
||||
text: 'IsConnected',
|
||||
text: 'Connection State',
|
||||
),
|
||||
if (Capabilities.supportsRequestMtuApi)
|
||||
PlatformButton(
|
||||
|
||||
@@ -410,7 +410,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.9.12"
|
||||
version: "0.10.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user