Refresh device and notification lists on return navigation

Subscribes the devices list and notifications list to a shared
RouteObserver so they refetch when a pushed route (e.g. device detail)
is popped, avoiding stale state after registering or updating a device.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-29 15:13:00 -04:00
co-authored by Claude Opus 4.7
parent eb91804c97
commit 926a902377
3 changed files with 40 additions and 2 deletions
+17 -1
View File
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
import '../model/device.dart';
import '../model/device_type.dart';
import '../navigation.dart';
import '../utils/friendly_date_formatter.dart';
import '../utils/oott_api.dart';
import '../widgets/status_badge.dart';
@@ -29,7 +30,7 @@ class DeviceList extends StatefulWidget {
State<DeviceList> createState() => _DeviceListState();
}
class _DeviceListState extends State<DeviceList> {
class _DeviceListState extends State<DeviceList> with RouteAware {
_DeviceFilter _filter = _DeviceFilter.newDevices;
List<Device> _devices = [];
bool _isLoading = true;
@@ -48,8 +49,23 @@ class _DeviceListState extends State<DeviceList> {
_fetchPage(0);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (route is ModalRoute<void>) {
routeObserver.subscribe(this, route);
}
}
@override
void didPopNext() {
_fetchPage(_currentPage);
}
@override
void dispose() {
routeObserver.unsubscribe(this);
_ownerDebounce?.cancel();
_ownerController.dispose();
super.dispose();