getPrimaryServices method

Future<List<WebBluetoothRemoteGATTService>> getPrimaryServices([
  1. String? serviceUUID
])

Get all the primary services on the current device.

Only services defined in RequestOptions and BluetoothScanFilter from when Bluetooth.requestDevice was called are available.

serviceUUID according to the docs this value is optional, but I can't find what would it would do if you set it anyways.

  • May throw SecurityError if a service's UUID is on a blocklist.

  • May throw NetworkError if the GATT server is not connected.

  • May throw InvalidStateError if GATT is null.

  • May throw NotFoundError if no services were found.

See:

Implementation

Future<List<WebBluetoothRemoteGATTService>> getPrimaryServices(
    [final String? serviceUUID]) async {
  final arguments = serviceUUID == null ? [] : [serviceUUID.toLowerCase()];
  final promise =
      _JSUtil.callMethod(_jsObject, "getPrimaryServices", arguments);
  final result = await _JSUtil.promiseToFuture(promise);
  if (result is List) {
    final items = <WebBluetoothRemoteGATTService>[];
    for (final item in result) {
      try {
        items.add(WebBluetoothRemoteGATTService.fromJSObject(item, device));
      } catch (e, stack) {
        if (e is UnsupportedError) {
          webBluetoothLogger.severe(
              "Could not convert primary service to BluetoothRemoteGATTService",
              e,
              stack);
        } else {
          rethrow;
        }
      }
    }
    return items;
  }
  return [];
}