In my flutter app, I have a ConnectivityStatus
widget which displays the current connection status of the app to my raspberry pi. In the initState
of my widget, I subscribe to a timer to check the connection every 5 seconds and update the state accordingly, then unsubscribe upon disposal.
The issue is, when multiple screens use the ConnectivityStatus
widget, such as in a stack navigator setup, I now have two concurrent subscriptions as neither instance has disposed. This causes many redundant, unneeded requests to occur.
What I really want is to either share a single instance of the widget across multiple screens, or have one global state multiple instances can access.
How can I achieve this or what are other recommended solutions to my problem?