From e2fd81aa6f3e3055587d832e6d2eeae2fec24d71 Mon Sep 17 00:00:00 2001 From: Nucleus Date: Mon, 1 Sep 2025 14:01:52 +0200 Subject: [PATCH] fix read state in case there is one alert for two places. Previously, you were unable to mark the second alert as read. --- lib/routes.dart | 19 +++++++++++++------ lib/views/alert_update_thread_view.dart | 2 +- lib/views/home/home_view.dart | 2 +- lib/views/my_place_detail_view.dart | 2 +- lib/views/warning_detail_view.dart | 6 +++++- lib/views/warnings_view.dart | 2 +- lib/widgets/warning_widget.dart | 12 +++++++++--- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/routes.dart b/lib/routes.dart index 130f0fac..980ab789 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -37,7 +37,8 @@ final routesProvider = Provider( onAddPlacePressed: () => context.go('/places/add'), onPlacePressed: (placeSubscriptionId) => context.go('/places/$placeSubscriptionId'), - onAlertPressed: (String alertId) => context.go('/alerts/$alertId'), + onAlertPressed: (String alertId, String subscriptionId) => + context.go('/alerts/$alertId/$subscriptionId'), onAlertUpdateThreadPressed: () => context.go('/alerts/update'), onSettingsPressed: () => context.go('/settings'), onAboutPressed: () => context.go('/about'), @@ -105,8 +106,8 @@ final routesProvider = Provider( String placeSubscriptionId = state.pathParameters["id"]!; return MyPlaceDetailScreen( placeSubscriptionId: placeSubscriptionId, - onAlertPressed: (String alertId) => - context.push('/alerts/$alertId'), + onAlertPressed: (String alertId, String subscriptionId) => + context.push('/alerts/$alertId/$subscriptionId'), onAlertUpdateThreadPressed: () => context.push('/alerts/update/'), ); @@ -119,16 +120,22 @@ final routesProvider = Provider( redirect: (context, state) => null, routes: [ GoRoute( - path: ':id', + path: ':id/:subscriptionId', builder: (context, state) { String id = state.pathParameters["id"]!; - return DetailScreen(warningIdentifier: id); + String subscriptionId = + state.pathParameters["subscriptionId"]!; + return DetailScreen( + warningIdentifier: id, + subscriptionId: subscriptionId, + ); }, ), GoRoute( path: 'update', builder: (context, state) => AlertUpdateThreadView( - onAlertPressed: (alertId) => context.go('/alerts/$alertId'), + onAlertPressed: (alertId, subscriptionId) => + context.go('/alerts/$alertId/$subscriptionId'), onAlertUpdateThreadPressed: () => context.go('/alerts/update'), ), diff --git a/lib/views/alert_update_thread_view.dart b/lib/views/alert_update_thread_view.dart index 27439e1f..5a5898fa 100644 --- a/lib/views/alert_update_thread_view.dart +++ b/lib/views/alert_update_thread_view.dart @@ -24,7 +24,7 @@ class AlertUpdateThreadView extends ConsumerStatefulWidget { super.key, }); - final void Function(String alertId) onAlertPressed; + final void Function(String alertId, String subscriptionId) onAlertPressed; final void Function() onAlertUpdateThreadPressed; @override diff --git a/lib/views/home/home_view.dart b/lib/views/home/home_view.dart index c9456650..2800d55f 100644 --- a/lib/views/home/home_view.dart +++ b/lib/views/home/home_view.dart @@ -33,7 +33,7 @@ class HomeView extends ConsumerStatefulWidget { final VoidCallback onAddPlacePressed; final void Function(String placeSubscriptionId) onPlacePressed; - final void Function(String alertId) onAlertPressed; + final void Function(String alertId, String subcriptionId) onAlertPressed; final VoidCallback onAlertUpdateThreadPressed; final VoidCallback onSettingsPressed; final VoidCallback onAboutPressed; diff --git a/lib/views/my_place_detail_view.dart b/lib/views/my_place_detail_view.dart index 9faf5608..71193451 100644 --- a/lib/views/my_place_detail_view.dart +++ b/lib/views/my_place_detail_view.dart @@ -17,7 +17,7 @@ class MyPlaceDetailScreen extends ConsumerWidget { }); final String placeSubscriptionId; - final void Function(String alertId) onAlertPressed; + final void Function(String alertId, String subscriptionId) onAlertPressed; final void Function() onAlertUpdateThreadPressed; @override diff --git a/lib/views/warning_detail_view.dart b/lib/views/warning_detail_view.dart index 61752948..b8456036 100644 --- a/lib/views/warning_detail_view.dart +++ b/lib/views/warning_detail_view.dart @@ -216,9 +216,11 @@ List _generateAssets(String text, {required BuildContext context}) { class DetailScreen extends ConsumerStatefulWidget { final String warningIdentifier; + final String subscriptionId; const DetailScreen({ required this.warningIdentifier, + required this.subscriptionId, super.key, }); @@ -235,7 +237,9 @@ class _DetailScreenState extends ConsumerState { WidgetsBinding.instance.addPostFrameCallback((_) async { var warning = ref.read(alertsProvider).firstWhere( - (alert) => alert.identifier == widget.warningIdentifier, + (alert) => + alert.identifier == widget.warningIdentifier && + alert.placeSubscriptionId == widget.subscriptionId, ); // update the read state of the alert diff --git a/lib/views/warnings_view.dart b/lib/views/warnings_view.dart index 7ecacc72..caec7620 100644 --- a/lib/views/warnings_view.dart +++ b/lib/views/warnings_view.dart @@ -14,7 +14,7 @@ class WarningsView extends ConsumerWidget { super.key, }); - final void Function(String alertId) onAlertPressed; + final void Function(String alertId, String subscriptionId) onAlertPressed; final VoidCallback onAlertUpdateThreadPressed; @override diff --git a/lib/widgets/warning_widget.dart b/lib/widgets/warning_widget.dart index 8aaa011b..b5f0a8ab 100644 --- a/lib/widgets/warning_widget.dart +++ b/lib/widgets/warning_widget.dart @@ -24,7 +24,7 @@ class WarningWidget extends ConsumerWidget { _updateThread = updateThread, _isMyPlaceWarning = isMyPlaceWarning; - final void Function(String id) onAlertPressed; + final void Function(String id, String subscriptionId) onAlertPressed; final void Function() onAlertUpdateThreadPressed; final List? _updateThread; final WarnMessage _warnMessage; @@ -87,7 +87,10 @@ class WarningWidget extends ConsumerWidget { return Card( child: InkWell( - onTap: () => onAlertPressed(_warnMessage.identifier), + onTap: () => onAlertPressed( + _warnMessage.identifier, + _warnMessage.placeSubscriptionId, + ), child: Padding( padding: const EdgeInsets.all(12), child: Row( @@ -188,7 +191,10 @@ class WarningWidget extends ConsumerWidget { Column( children: [ IconButton( - onPressed: () => onAlertPressed(_warnMessage.identifier), + onPressed: () => onAlertPressed( + _warnMessage.identifier, + _warnMessage.placeSubscriptionId, + ), icon: const Icon(Icons.read_more), ), (_updateThread != null && _updateThread.length > 1)