getDescriptors method
Return a list BluetoothDescriptors for this characteristic.
-
May throw SecurityError if the UUID is on a blocklist.
-
May throw NetworkError if the device is not connected or if there is an error with the communication.
-
May throw StateError if the characteristic is null.
-
May throw NotFoundError if the descriptor could not be found.
See: BluetoothDescriptor.
Implementation
Future<List<BluetoothDescriptor>> getDescriptors() async {
try {
final descriptors = await _characteristic.getDescriptors();
return descriptors.map(BluetoothDescriptor.new).toList();
} catch (e) {
final error = e.toString().trim();
if (error.startsWith("NetworkError")) {
throw NetworkError.withUUid(uuid);
} else if (error.startsWith("SecurityError")) {
throw SecurityError(uuid, error);
} else if (error.startsWith("InvalidStateError")) {
throw StateError("Characteristic is null");
} else if (error.startsWith("NotFoundError")) {
throw NotFoundError.forDescriptor("ALL", uuid);
}
rethrow;
}
}