Is there a way to broadcast data from one widget to other widgets? Similar to a BroadcastReceiver on Android or NSNotificationCenter on iOS.
Specifically, I'm trying to detect when a Navigator pops or pushes a new view. I added navigatorObservers to MaterialApp. And when a widget comes back to the foreground, I want to be able to notify it by broadcasting changes from didPush and didPop with the actual route that's in the current foreground
Navigator.push
returns aFuture
that will complete whenNavigator.pop
is called (and this can optionally be used to pass data back to the widget that calledpush
). So for example suppose your login button has thisonPressed
handler:When your login page calls
Navigator.pop(true)
, theFuture
will complete with a value oftrue
which will be assigned to theisLoggedIn
variable. (You'll getnull
if the user uses the back button to return to the previous screen.)This is how
showDialog
works as well.