feat: display Sensors from repo on sensor list
This commit is contained in:
@@ -10,9 +10,7 @@ class SensorListScreen extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// TODO: replace Placeholder with AsyncValue-driven list.
|
||||
// final sensors = ref.watch(sensorsProvider); // define a FutureProvider
|
||||
|
||||
final sensors = ref.watch(sensorsProvider);
|
||||
final selectedId = ref.watch(selectedSensorIdProvider);
|
||||
|
||||
return Scaffold(
|
||||
@@ -34,9 +32,36 @@ class SensorListScreen extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
// TODO: ListView.builder with sensor tiles.
|
||||
// Highlight tile whose id == selectedId.
|
||||
const Expanded(child: Placeholder()),
|
||||
Expanded(
|
||||
child: sensors.when(
|
||||
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(
|
||||
@@ -44,7 +69,7 @@ class SensorListScreen extends ConsumerWidget {
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (_) => const BleProvisionSheet(),
|
||||
),
|
||||
).then((_) => ref.invalidate(sensorsProvider)),
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user