Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectNotification callback before showing first screen #99

Closed
hartmannj opened this issue Sep 13, 2018 · 13 comments
Closed

SelectNotification callback before showing first screen #99

hartmannj opened this issue Sep 13, 2018 · 13 comments

Comments

@hartmannj
Copy link

Is it possible to somehow get the callback before showing the root page? Basically to determine which page to load. I've tried a bunch of things but could not get it to work so far.
In my case I would like to show a different page as root if the app gets newly started via a notification callback. I can't just do pushReplacment or pushAndRemoveUntil inside the active root page since I wanna preserve the stack in case the app has been opened before the callback.

@MaikuB
Copy link
Owner

MaikuB commented Sep 13, 2018

couldn't you just check if Navigator.canPop(context) returns false and if it does then you could use pushReplacement or pushAndRemoveUntil? If you weren't on the root page when the app has already been opened and the navigation stack isn't empty then it should return true

@hartmannj
Copy link
Author

That would be possible if the root page is always the same otherwise logic gets more complicated, also if there are form elements on it which might be filled out already.
Another thing I've noticed is that sometimes the root page shows up very briefly before the callback page is displayed which would not be the ideal user experience especially in case of pushReplacement.

@MaikuB
Copy link
Owner

MaikuB commented Sep 20, 2018

I'm not sure there's a way around it at the moment with the flow of when things get executed on the platform side too. One thought I've had that may or may not work is to expose a method through the plugin that you could call in the main function to determine if the app is being launched due to a notification, you'd use the result of that to change the home page (https://docs.flutter.io/flutter/material/MaterialApp/home.html). initState can't be async but I believe main can be

@MaikuB
Copy link
Owner

MaikuB commented Sep 26, 2018

I've release a new version of the plugin (0.3.8) that adds a getNotificationAppLaunchDetails()that you could use in the main function as I mentioned above so that you can change the default/home route. The select notification callback will still be called but you could use the results of the previous method to prevent it from running code (e.g. navigating to another screen) if needed. Try it out and see how you go

@hartmannj
Copy link
Author

Awesome, works great! Tested it both on iOS and Android.

@onimeshc-iprogrammer
Copy link

The didNotificationLaunchApp flag once set to true always remains true, it breaks my other flows

@MaikuB
Copy link
Owner

MaikuB commented Apr 14, 2020

@onimeshc-iprogrammer it is only meant to stay true within the same app session if a notification launched the app but not if it's been restarted. If that is still the same scenario you're referring to then this is working as intended and you'll need to resolve within your own app as it's a method to query the launch state

@onimeshc-iprogrammer
Copy link

Is there any way to reset the flag programmatically?

@MaikuB
Copy link
Owner

MaikuB commented Apr 14, 2020

No and there are no plans to. You'll need to fix the logic in your own app, which I would guess is calling the method multiple times

@onimeshc-iprogrammer
Copy link

Let me understand, I have all my routes been set using the router, when I launch the app from notification after being killed I get the flag as true, which is fine, later when my app is in active/minimised state I yet get the flag as true.

And please can I get about what method do I need to call multiple times?

@MaikuB
Copy link
Owner

MaikuB commented Apr 14, 2020

Let me understand, I have all my routes been set using the router, when I launch the app from notification after being killed I get the flag as true, which is fine, later when my app is in active/minimised state I yet get the flag as true.

Yes that is expected, it's still the same app session. Launching is about if the app was started where before then it not running at all i.e. being in the background doesn't count as it was just suspended.

And please can I get about what method do I need to call multiple times?

Sorry but I don't understanding what you mean as the wording doesn't make sense. Can you rephrase? If you mean how to stop calling the same method, you could track some state in your own app to make sure it only happens once

@yokemanann
Copy link

yokemanann commented Jun 27, 2020

@MaikuB Is it possible to not open the app while onSelectNotification callback is triggered as usual?

@MaikuB
Copy link
Owner

MaikuB commented Jun 27, 2020

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants