slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
582 stars 128 forks source link

Provide an example to facilitate redirecting to a page/screen on clicking of a push notification #546

Open braj065 opened 1 year ago

braj065 commented 1 year ago

Please provide a beamer example which can be followed to handle routing to screens on clicking of push notifications.

It would be great if the beaming can be independent of BuildContext. Since push notifications are a stream which is handled in flutter's main file before runApp(). So buildcontext won't be available in that code section.

rivella50 commented 1 year ago

I'm using a StateNotifierProvider to accomplish this: In the push notifications handler i update the state object according to the message's content which is then read and processed in the navigation widget:

ref.listen<NavigationState>(navigationStateProvider, (previous, next) {
   _currentTabIndex = next.currentTabIndex;
   _beamerDelegate.beamToNamed(ref.read(navigationStateProvider.notifier).currentPath);
});
slovnicki commented 1 year ago

Currently you could achieve this with some custom calls to specific BeamerDelegate, as @rivella50 suggested. I've been thinking about this and will be adding this feature in Beamer v2. It will also ease managing deep-links that need to pass some complex auth redirection first before landing on the deep-link.

braj065 commented 1 year ago

@slovnicki Please add this to v2 milestone.