main
 1import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_backend.dart';
 2import 'package:blood_pressure_app/features/bluetooth/ui/input_card.dart';
 3import 'package:flutter/material.dart';
 4import 'package:blood_pressure_app/l10n/app_localizations.dart';
 5
 6/// A pairing dialoge with a single bluetooth device.
 7class DeviceSelection extends StatelessWidget {
 8  /// Create a pairing dialoge with a single bluetooth device.
 9  const DeviceSelection({super.key,
10    required this.scanResults,
11    required this.onAccepted,
12  });
13
14  /// The name of the device trying to connect.
15  final List<BluetoothDevice> scanResults;
16
17  /// Called when the user accepts the device.
18  final void Function(BluetoothDevice) onAccepted;
19
20  Widget _buildDeviceTile(BuildContext context, BluetoothDevice dev) => ListTile(
21    title: Text(dev.name),
22    trailing: FilledButton(
23      onPressed: () => onAccepted(dev),
24      child: Text(AppLocalizations.of(context)!.connect),
25    ),
26    onTap: () => onAccepted(dev),
27  );
28
29  @override
30  Widget build(BuildContext context) {
31    assert(scanResults.isNotEmpty);
32    return InputCard(
33      title: Text(AppLocalizations.of(context)!.availableDevices),
34      child: ListView(
35        shrinkWrap: true,
36        children: [
37          for (final dev in scanResults)
38            _buildDeviceTile(context, dev),
39        ]
40      ),
41    );
42  }
43
44}