How do I trigger a navigation from a stream?

44 views
Skip to first unread message

Malibu

unread,
Aug 3, 2023, 8:51:13 AM8/3/23
to Dart Misc
I have my app connecting to a server and there are asynchronous messages that come back through connectanum and dart streams.  One of these messages is to remove the user from the group they are active in, which means in response to this message the client app needs to navigate to a previous page and essentially stop the stop the user from navigating inside the group they are currently seeing.

How is this done in flutter?  I have read about how to use GlobalKey<NavigationState> to remove the need for context, so I used this page to make a NavigationService:


I use getit so I skip the singleton stuff and just have a normal class but basically it gets the GlobalKey<NavigationState> and you set up MaterialApp with navigationKey: _navService.navigationLKey.  But when I do this the currentState is null.

Is there a better way to Navigate inside a stream or am I on the right track and just making a mistake somewhere?  Thanks for the help.

Malibu

unread,
Aug 3, 2023, 9:18:06 AM8/3/23
to Dart Misc, Malibu

It seems to work anyway.

You set up a listener on a stream in the setState of the page you want to navigate from with the navigation inside and trigger it through the stream when it's time.

That's why I post these questions, because I inevitably find the answer ten minutes later after searching for hours!  Thanks for the help.  If anyone feels like this is the wrong thing to do please speak up.

Malibu

unread,
Aug 3, 2023, 9:39:02 AM8/3/23
to Dart Misc, Malibu
That should read 'initState' not 'setState'.
Reply all
Reply to author
Forward
0 new messages