feat: display room name in tag list, detail sheet

This commit is contained in:
2026-05-19 20:37:08 +02:00
parent 4877ff9b71
commit 0c18ed15fe
2 changed files with 29 additions and 11 deletions
+12 -2
View File
@@ -75,6 +75,7 @@ class _TagDetailSheetState extends ConsumerState<TagDetailSheet> {
final tagAsync = ref.watch(tagProvider(widget.tagId));
final occupancy = ref.watch(roomOccupancyProvider);
final trackedTag = ref.watch(trackedTagProvider);
final roomsAsync = ref.watch(roomsProvider);
return tagAsync.when(
loading: () => const SizedBox(
@@ -120,7 +121,10 @@ class _TagDetailSheetState extends ConsumerState<TagDetailSheet> {
Row(
children: [
Icon(
tag.currentRoomId != null
tag.lastSeen?.isAfter(
DateTime.now().subtract(.new(minutes: 3)),
) ??
false
? Icons.label
: Icons.label_outline,
),
@@ -159,7 +163,13 @@ class _TagDetailSheetState extends ConsumerState<TagDetailSheet> {
_InfoRow(
label: 'Current room',
value: currentRoomId != null
? 'Room $currentRoomId'
? (roomsAsync.whenOrNull(
data: (data) => data
.where((r) => r.id == currentRoomId)
.firstOrNull
?.name,
) ??
'Not detected')
: 'Not detected',
),
if (tag.lastSeen != null)
+17 -9
View File
@@ -13,6 +13,7 @@ class TagListScreen extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final tags = ref.watch(tagsProvider);
final occupancy = ref.watch(roomOccupancyProvider);
final roomsAsync = ref.watch(roomsProvider);
// Invert occupancy map: tagId -> roomId
final tagRoomMap = <String, int>{};
@@ -52,10 +53,17 @@ class TagListScreen extends ConsumerWidget {
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: list
.map((t) => _TagTile(
tag: t,
roomId: tagRoomMap[t.tagId],
))
.map(
(t) => _TagTile(
tag: t,
roomName: roomsAsync.whenOrNull(
data: (data) => data
.where((r) => r.id == tagRoomMap[t.tagId])
.firstOrNull
?.name,
),
),
)
.toList(),
),
);
@@ -70,20 +78,20 @@ class TagListScreen extends ConsumerWidget {
}
class _TagTile extends StatelessWidget {
const _TagTile({required this.tag, required this.roomId});
const _TagTile({required this.tag, required this.roomName});
final Tag tag;
final int? roomId;
final String? roomName;
@override
Widget build(BuildContext context) {
final isDetected = roomId != null;
final isDetected = roomName != null;
return ListTile(
leading: Icon(isDetected ? Icons.label : Icons.label_outline),
title: Text(tag.name),
subtitle: Text(isDetected ? 'Room $roomId' : 'Not detected'),
subtitle: Text(isDetected ? roomName! : 'Not detected'),
trailing: const Icon(Icons.chevron_right),
onTap: () => showTagDetailSheet(context, tag.id),
);
}
}
}