Suragch
Nov 8, 2023

--

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.

--

--

Suragch
Suragch

Written by Suragch

Flutter and Dart developer. Twitter: @suragch1, Email: suragch@suragch.dev

No responses yet