getBleService method

Future<BluetoothService> getBleService({
  1. dynamic attempts = 2,
})

Implementation

Future<BluetoothService> getBleService({attempts = 2}) async {
  for (int i = 0; i < attempts; i++) {
    List<BluetoothService> services = await discoverServices();
    final bleService = services
        .where(
          (service) => service.uuid.str == ViamBluetoothUUIDs.serviceUUID,
        )
        .firstOrNull;
    if (bleService != null) return bleService;
    if (i < attempts - 1) {
      await clearGattCache();
    }
  }
  throw Exception('bleService not found after $attempts attempts');
}