1

I'm guessing that the following code will FIRST return an empty list, and then later (when the future completes), it will return the actual data provided by the future.

That's all good ... but I'm wondering if my list-data will be retained and cached (thats what I want), or if it will be purged when the future completes.

In other words, does the "historyItemsProvider" rebuild TWICE, or 3 times from the watch below?

final historyItemsProvider =
    StateProvider<List<ValuesBehaviorAssessMsg>>((ref) {
  // holds all data returned by the API
  final data = ref.watch(loadHistoryFutureProvider);
  List<ValuesBehaviorAssessMsg> response = [];
  data.whenData((vcm) => response = vcm.items);
  return response;
});
sidrao2006
  • 1,228
  • 2
  • 10
  • 32
Dewey
  • 756
  • 6
  • 17
  • 1
    it should be fine as long as the providers are not of autodispose type and they stop being watched, only when data finally returns somehting is when response will actually give you a different list, but if you want to try to create a ProviderObserver so you can see yourself how many times it rebuilds – EdwynZN Jan 06 '21 at 01:50
  • 1
    @EdwynZN I'm really asking if the provider will RETAIN the data ... for example, could I use this provider on another screen/route/page without it doing more ASYNC work?? Is it cached? – Dewey Feb 21 '21 at 20:11
  • 1
    yes, as long as you don't use autoDispose that provider will remain active the whole life cycle of your app – EdwynZN Feb 22 '21 at 17:42

0 Answers0