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 tagAsync = ref.watch(tagProvider(widget.tagId));
final occupancy = ref.watch(roomOccupancyProvider); final occupancy = ref.watch(roomOccupancyProvider);
final trackedTag = ref.watch(trackedTagProvider); final trackedTag = ref.watch(trackedTagProvider);
final roomsAsync = ref.watch(roomsProvider);
return tagAsync.when( return tagAsync.when(
loading: () => const SizedBox( loading: () => const SizedBox(
@@ -120,7 +121,10 @@ class _TagDetailSheetState extends ConsumerState<TagDetailSheet> {
Row( Row(
children: [ children: [
Icon( Icon(
tag.currentRoomId != null tag.lastSeen?.isAfter(
DateTime.now().subtract(.new(minutes: 3)),
) ??
false
? Icons.label ? Icons.label
: Icons.label_outline, : Icons.label_outline,
), ),
@@ -159,7 +163,13 @@ class _TagDetailSheetState extends ConsumerState<TagDetailSheet> {
_InfoRow( _InfoRow(
label: 'Current room', label: 'Current room',
value: currentRoomId != null value: currentRoomId != null
? 'Room $currentRoomId' ? (roomsAsync.whenOrNull(
data: (data) => data
.where((r) => r.id == currentRoomId)
.firstOrNull
?.name,
) ??
'Not detected')
: 'Not detected', : 'Not detected',
), ),
if (tag.lastSeen != null) if (tag.lastSeen != null)
+15 -7
View File
@@ -13,6 +13,7 @@ class TagListScreen extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final tags = ref.watch(tagsProvider); final tags = ref.watch(tagsProvider);
final occupancy = ref.watch(roomOccupancyProvider); final occupancy = ref.watch(roomOccupancyProvider);
final roomsAsync = ref.watch(roomsProvider);
// Invert occupancy map: tagId -> roomId // Invert occupancy map: tagId -> roomId
final tagRoomMap = <String, int>{}; final tagRoomMap = <String, int>{};
@@ -52,10 +53,17 @@ class TagListScreen extends ConsumerWidget {
child: ListView( child: ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
children: list children: list
.map((t) => _TagTile( .map(
(t) => _TagTile(
tag: t, tag: t,
roomId: tagRoomMap[t.tagId], roomName: roomsAsync.whenOrNull(
)) data: (data) => data
.where((r) => r.id == tagRoomMap[t.tagId])
.firstOrNull
?.name,
),
),
)
.toList(), .toList(),
), ),
); );
@@ -70,18 +78,18 @@ class TagListScreen extends ConsumerWidget {
} }
class _TagTile extends StatelessWidget { class _TagTile extends StatelessWidget {
const _TagTile({required this.tag, required this.roomId}); const _TagTile({required this.tag, required this.roomName});
final Tag tag; final Tag tag;
final int? roomId; final String? roomName;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isDetected = roomId != null; final isDetected = roomName != null;
return ListTile( return ListTile(
leading: Icon(isDetected ? Icons.label : Icons.label_outline), leading: Icon(isDetected ? Icons.label : Icons.label_outline),
title: Text(tag.name), title: Text(tag.name),
subtitle: Text(isDetected ? 'Room $roomId' : 'Not detected'), subtitle: Text(isDetected ? roomName! : 'Not detected'),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () => showTagDetailSheet(context, tag.id), onTap: () => showTagDetailSheet(context, tag.id),
); );