feat: display Sensors from repo on sensor list

This commit is contained in:
2026-05-12 16:40:56 +02:00
parent 78818981c3
commit ddb8bfb81e
+32 -7
View File
@@ -10,9 +10,7 @@ class SensorListScreen extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
// TODO: replace Placeholder with AsyncValue-driven list. final sensors = ref.watch(sensorsProvider);
// final sensors = ref.watch(sensorsProvider); // define a FutureProvider
final selectedId = ref.watch(selectedSensorIdProvider); final selectedId = ref.watch(selectedSensorIdProvider);
return Scaffold( return Scaffold(
@@ -34,9 +32,36 @@ class SensorListScreen extends ConsumerWidget {
), ),
], ],
), ),
// TODO: ListView.builder with sensor tiles. Expanded(
// Highlight tile whose id == selectedId. child: sensors.when(
const Expanded(child: Placeholder()), loading: () =>
const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(child: Text(e.toString())),
data: (list) => list.isEmpty
? const Center(child: Text('No sensors enrolled yet'))
: ListView.builder(
itemCount: list.length,
itemBuilder: (context, i) {
final sensor = list[i];
final isSelected =
selectedId == sensor.id.toString();
return ListTile(
selected: isSelected,
leading: Icon(sensor.isPlaced
? Icons.sensors
: Icons.sensors_off_outlined),
title: Text(sensor.displayName),
subtitle: Text(sensor.isPlaced
? 'Placed'
: 'Not placed on floor plan'),
trailing: const Icon(Icons.chevron_right),
onTap: () =>
context.push('/sensors/${sensor.id}'),
);
},
),
),
),
], ],
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
@@ -44,7 +69,7 @@ class SensorListScreen extends ConsumerWidget {
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
builder: (_) => const BleProvisionSheet(), builder: (_) => const BleProvisionSheet(),
), ).then((_) => ref.invalidate(sensorsProvider)),
child: const Icon(Icons.add), child: const Icon(Icons.add),
), ),
); );