Here is how to handle sharing state with other widgets. The technique depends on where the widgets are located:
- Child widgets: Pass the desired state or a reference to the manager object into the widget as a constructor parameter.
- A second screen: Pass the state in through the constructor or as an argument with your navigation router (like GoRouter).
- A distant widget in your app: (option 1) Have a top-level app manager class with notifiers to update various parts of your app. (option 2) Have an app manager class that you register as a singleton with GetIt. Then you can use GetIt to grab a reference to the manager class whenever you need it. (option 3) Save the state to local storage and look it up whenever you need it.