'Push route based on push notification

I'm having trouble wrapping my head around how best to implement pushing to a certain route when a push notification is received.

My current setup is that I have a login screen, then a home screen with three pages, and on one of those pages you can tap through to a list of chats, and finally you can tap through into those chats. So there are quite a few levels of navigation going on.

I have notifications working with firebase cloud messaging, but what I'm struggling with is how I should push a chat view when the user taps the notification. I've set a handler with:

FirebaseMessaging.onBackgroundMessage(_fcmBackgroundHandler);

This handler gets the chat id from the notification data payload. My plan is to then use this id to navigate to the corresponding chat view.

I want to do something like:

  • push to the chat list view
  • load all the chats
  • if there is a chat with the same id as the one in the payload then push that chat
  • if there isn't then do nothing or throw an error.

The problem is that I don't think I can just push the chat list window as soon as the app opens, because the user might have left the app in a completely different part of the navigation tree, and so pushing the chat list view on top of that would make no sense, not to mention the fact that some change notifier providers needed for the chat list view might not be in the context. I need some kind of way to guarantee that a certain route structure has been followed, but to do that I'd need to know what route the app is on when launched, and then react to that.

Has anyone got any experience with implementing this kind of feature?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source