From 845276bac774ae46e6bee3e44941e4a11748e10a Mon Sep 17 00:00:00 2001 From: dvdrw Date: Tue, 19 May 2026 20:13:31 +0200 Subject: [PATCH] feat: make sensor and tag lists refreshable --- lib/features/sensors/sensor_list_screen.dart | 41 +++++++++++++------- lib/features/tags/tag_list_screen.dart | 36 +++++++++++++---- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/lib/features/sensors/sensor_list_screen.dart b/lib/features/sensors/sensor_list_screen.dart index 9f4d517..8440835 100644 --- a/lib/features/sensors/sensor_list_screen.dart +++ b/lib/features/sensors/sensor_list_screen.dart @@ -40,25 +40,40 @@ class SensorListScreen extends ConsumerWidget { error: (e, _) => Center(child: Text(e.toString())), data: (list) { if (list.isEmpty) { - return const Center(child: Text('No sensors enrolled yet')); + return RefreshIndicator( + onRefresh: () => ref.refresh(sensorsProvider.future), + child: const CustomScrollView( + physics: AlwaysScrollableScrollPhysics(), + slivers: [ + SliverFillRemaining( + child: Center( + child: Text('No sensors enrolled yet')), + ), + ], + ), + ); } final unplaced = list.where((s) => !s.isPlaced).toList(); final placed = list.where((s) => s.isPlaced).toList(); - return ListView( - children: [ - if (unplaced.isNotEmpty) ...[ - _SectionHeader( - label: 'Unplaced', count: unplaced.length), - ...unplaced.map((s) => _SensorTile(sensor: s)), + return RefreshIndicator( + onRefresh: () => ref.refresh(sensorsProvider.future), + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + if (unplaced.isNotEmpty) ...[ + _SectionHeader( + label: 'Unplaced', count: unplaced.length), + ...unplaced.map((s) => _SensorTile(sensor: s)), + ], + if (placed.isNotEmpty) ...[ + _SectionHeader( + label: 'Placed', count: placed.length), + ...placed.map((s) => _SensorTile(sensor: s)), + ], ], - if (placed.isNotEmpty) ...[ - _SectionHeader( - label: 'Placed', count: placed.length), - ...placed.map((s) => _SensorTile(sensor: s)), - ], - ], + ), ); }, ), diff --git a/lib/features/tags/tag_list_screen.dart b/lib/features/tags/tag_list_screen.dart index ad91841..132ae80 100644 --- a/lib/features/tags/tag_list_screen.dart +++ b/lib/features/tags/tag_list_screen.dart @@ -29,15 +29,35 @@ class TagListScreen extends ConsumerWidget { error: (e, _) => Center(child: Text(e.toString())), data: (list) { if (list.isEmpty) { - return const Center(child: Text('No tags enrolled yet')); + return RefreshIndicator( + onRefresh: () { + ref.invalidate(roomOccupancyProvider); + return ref.refresh(tagsProvider.future); + }, + child: const CustomScrollView( + physics: AlwaysScrollableScrollPhysics(), + slivers: [ + SliverFillRemaining( + child: Center(child: Text('No tags enrolled yet')), + ), + ], + ), + ); } - return ListView( - children: list - .map((t) => _TagTile( - tag: t, - roomId: tagRoomMap[t.tagId], - )) - .toList(), + return RefreshIndicator( + onRefresh: () { + ref.invalidate(roomOccupancyProvider); + return ref.refresh(tagsProvider.future); + }, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: list + .map((t) => _TagTile( + tag: t, + roomId: tagRoomMap[t.tagId], + )) + .toList(), + ), ); }, ),