mardi 30 mars 2021

How to notify a high level Provider from a singleton? (Flutter design pattern)

In my app I have a singleton SettingsData which holds all of the user's settings data (instead of having to read asynchronously from SharedPreferences every time do it once). I create that singleton before calling RunApp(...).

On top of that I have a Widget CurrentItems (which is a ChangeNotifierProvider),a business logic representing the items to be shown to the user based on his current settings/preferences.

Upon any change in the users settings(debounced of course), I want to notify the CurrentItems object so it can fetch relevant items from the server, and after getting new relevant items update the UI (the last part is already working since CurrentItems is a ChangeNotifierProvider)

What would be a reasonable way/pattern to achieve that? For instance, making SettingsData a ChangeNotifierProvider and CurrentItems a Consumer is not a good option since CurrentItems is a high-level item, meaning that the entire UI would be rebuilt on every settings change before new items were fetched from the server.

Aucun commentaire:

Enregistrer un commentaire