Push notification tap redirect to corressponding ticket or task

This commit is contained in:
2026-03-02 21:09:38 +08:00
parent eb49329b16
commit 5713581992
3 changed files with 75 additions and 58 deletions
+21 -20
View File
@@ -482,8 +482,13 @@ Future<void> main() async {
>()
?.createNotificationChannel(channel);
// global navigator key used for snackbars/navigation from notification
final navigatorKey = GlobalKey<NavigatorState>();
// Create the global provider container BEFORE initializing local
// notifications, because the tap callback needs to write to it and
// flutter_local_notifications may fire the callback synchronously if
// the app was launched by tapping a notification.
_globalProviderContainer = ProviderContainer(
observers: [NotificationSoundObserver()],
);
// initialize the local notifications plugin so we can post alerts later
await NotificationService.initialize(
@@ -505,36 +510,32 @@ Future<void> main() async {
}
}
// Update the pending navigation provider
if (ticketId != null && ticketId.isNotEmpty) {
_globalProviderContainer
.read(pendingNotificationNavigationProvider.notifier)
.state = (
type: 'ticket',
id: ticketId,
);
} else if (taskId != null && taskId.isNotEmpty) {
// Update the pending navigation provider.
// Prefer task over ticket — assignment notifications include both
// IDs but the primary entity is the task.
if (taskId != null && taskId.isNotEmpty) {
_globalProviderContainer
.read(pendingNotificationNavigationProvider.notifier)
.state = (
type: 'task',
id: taskId,
);
} else if (ticketId != null && ticketId.isNotEmpty) {
_globalProviderContainer
.read(pendingNotificationNavigationProvider.notifier)
.state = (
type: 'ticket',
id: ticketId,
);
}
}
},
);
// Create the global provider container
_globalProviderContainer = ProviderContainer();
runApp(
ProviderScope(
observers: [NotificationSoundObserver()],
child: NotificationBridge(
navigatorKey: navigatorKey,
child: const TasqApp(),
),
UncontrolledProviderScope(
container: _globalProviderContainer,
child: const NotificationBridge(child: TasqApp()),
),
);