1

I am working on a flutter application that is similar to WhatsApp. But I have encountered a problem of which I am unable to find a solution. I have linked Firebase Background Messaging Handler to my application in order to launch a screen in terminated state as soon as a push notification arrives. However, so far, in short, I am unable to open a page on the arrival of notification. Because the following link https://firebase.flutter.dev/docs/messaging/usage/ suggests that firebaseMessagingBackgroundHandler must be located on the top level before runApp(MyApp()); That is why I am unable to use Navigator.pushNamed(context,Strings.routeHome,) to open some specific page. As context in not available at this point. If you could suggest some sort of solution to resolve this issue. Thank you.

1 Answers1

0

The code which pushes the page should be initiated from the initstate of the very first page of your app, and that should be done conditionally using whatever firebase brings from the push notification. On top level, firebase should check if there is a need for the page to be pushed, if yes, then that should be passed down to the first page of your app, and then it should decide if it needs to push the app, you cannot directly push a page. The first page needs to be launched. You can put a loader on the first page till it does all the checking stuff

Ahmad Raza
  • 758
  • 7
  • 26