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 · 5 comments

Comments

@hartmannj
Copy link

@hartmannj hartmannj commented Sep 13, 2018

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

This comment has been minimized.

Copy link
Owner

@MaikuB 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

This comment has been minimized.

Copy link
Author

@hartmannj hartmannj commented Sep 14, 2018

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

This comment has been minimized.

Copy link
Owner

@MaikuB 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

This comment has been minimized.

Copy link
Owner

@MaikuB 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

This comment has been minimized.

Copy link
Author

@hartmannj hartmannj commented Sep 28, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.