1import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_device.dart';
 2import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_discovery.dart';
 3import 'package:blood_pressure_app/features/bluetooth/backend/flutter_blue_plus/fbp_manager.dart';
 4import 'package:flutter_blue_plus/flutter_blue_plus.dart' show Guid;
 5
 6/// BluetoothDeviceDiscovery implementation for the 'flutter_blue_plus' package
 7final class FlutterBluePlusDiscovery extends BluetoothDeviceDiscovery<FlutterBluePlusManager> {
 8  /// constructor
 9  FlutterBluePlusDiscovery(super.manager);
10
11  @override
12  Stream<List<BluetoothDevice>> get discoverStream => manager.backend.scanResults.map(
13    (devices) => devices.map(manager.createDevice).toList()
14  );
15
16  @override
17  Future<void> backendStart(String serviceUuid) async {
18    try {
19      await manager.backend.startScan(
20        // no timeout, the user knows best how long scanning is needed
21        withServices: [ Guid(serviceUuid) ],
22        // Not all devices are found using this configuration (https://pub.dev/packages/flutter_blue_plus#scanning-does-not-find-my-device).
23      );
24    } catch (e) {
25      onDiscoveryError(e);
26    }
27  }
28
29  @override
30  Future<void> backendStop() => manager.backend.stopScan();
31}