getDescriptor method

Future<BluetoothDescriptor> getDescriptor(
  1. String descriptorUUID
)

Return a BluetoothDescriptor for this characteristic.

descriptorUUID the UUID of the descriptor.

  • 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<BluetoothDescriptor> getDescriptor(final String descriptorUUID) async {
  try {
    final descriptor = await _characteristic.getDescriptor(descriptorUUID);
    return BluetoothDescriptor(descriptor);
  } 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(descriptorUUID, uuid);
    }
    rethrow;
  }
}