mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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:
co-authored by
Claude Opus 4.7
parent
eb91804c97
commit
926a902377
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
|
|
||||||
import '../model/device.dart';
|
import '../model/device.dart';
|
||||||
import '../model/device_type.dart';
|
import '../model/device_type.dart';
|
||||||
|
import '../navigation.dart';
|
||||||
import '../utils/friendly_date_formatter.dart';
|
import '../utils/friendly_date_formatter.dart';
|
||||||
import '../utils/oott_api.dart';
|
import '../utils/oott_api.dart';
|
||||||
import '../widgets/status_badge.dart';
|
import '../widgets/status_badge.dart';
|
||||||
@@ -29,7 +30,7 @@ class DeviceList extends StatefulWidget {
|
|||||||
State<DeviceList> createState() => _DeviceListState();
|
State<DeviceList> createState() => _DeviceListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DeviceListState extends State<DeviceList> {
|
class _DeviceListState extends State<DeviceList> with RouteAware {
|
||||||
_DeviceFilter _filter = _DeviceFilter.newDevices;
|
_DeviceFilter _filter = _DeviceFilter.newDevices;
|
||||||
List<Device> _devices = [];
|
List<Device> _devices = [];
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
@@ -48,8 +49,23 @@ class _DeviceListState extends State<DeviceList> {
|
|||||||
_fetchPage(0);
|
_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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
routeObserver.unsubscribe(this);
|
||||||
_ownerDebounce?.cancel();
|
_ownerDebounce?.cancel();
|
||||||
_ownerController.dispose();
|
_ownerController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../model/notification.dart' as oott_model;
|
import '../model/notification.dart' as oott_model;
|
||||||
|
import '../navigation.dart';
|
||||||
import '../utils/friendly_date_formatter.dart';
|
import '../utils/friendly_date_formatter.dart';
|
||||||
import '../utils/oott_api.dart';
|
import '../utils/oott_api.dart';
|
||||||
import '../utils/ui_snackbars.dart';
|
import '../utils/ui_snackbars.dart';
|
||||||
@@ -35,7 +36,7 @@ class NotificationsList extends StatefulWidget {
|
|||||||
State<NotificationsList> createState() => _NotificationsListState();
|
State<NotificationsList> createState() => _NotificationsListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NotificationsListState extends State<NotificationsList> {
|
class _NotificationsListState extends State<NotificationsList> with RouteAware {
|
||||||
_NotificationFilter _filter = _NotificationFilter.newOnly;
|
_NotificationFilter _filter = _NotificationFilter.newOnly;
|
||||||
Timer? _notificationTimer;
|
Timer? _notificationTimer;
|
||||||
|
|
||||||
@@ -54,8 +55,23 @@ class _NotificationsListState extends State<NotificationsList> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
routeObserver.unsubscribe(this);
|
||||||
_notificationTimer?.cancel();
|
_notificationTimer?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,17 @@ const List<_NavDest> _destinations = [
|
|||||||
(icon: Icons.info_outline, activeIcon: Icons.info, label: 'About'),
|
(icon: Icons.info_outline, activeIcon: Icons.info, label: 'About'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Observer used to notify subscribed routes when another route is pushed
|
||||||
|
// on top of or popped from them, so they can refresh stale data.
|
||||||
|
final RouteObserver<ModalRoute<void>> routeObserver =
|
||||||
|
RouteObserver<ModalRoute<void>>();
|
||||||
|
|
||||||
// Routes definitions
|
// Routes definitions
|
||||||
final GoRouter router = GoRouter(
|
final GoRouter router = GoRouter(
|
||||||
initialLocation: '/notifications',
|
initialLocation: '/notifications',
|
||||||
routes: [
|
routes: [
|
||||||
ShellRoute(
|
ShellRoute(
|
||||||
|
observers: [routeObserver],
|
||||||
builder: (context, state, child) {
|
builder: (context, state, child) {
|
||||||
return MainShell(child: child);
|
return MainShell(child: child);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user