what I'm trying to achieve here is a functionality that firstly tries to load the data stored in local storage (if any) and then fetch the new data from the API and displays and stores them in local storage.
I'm thinking of two ways to do that but since I'm not familiar with Flutter, I actually don't know how exactly to do that.
Imagine doing that in React Js/Native:
First Way
- use a state hook to store the data
- display an activity indicator if state is null/empty
- read the data from storage and display them to user
- fetch the new data, update the state and store the new data in local storage
Second Way
- use a state hook to store the data
- display an activity indicator if state is null/empty
- read the data from storage and display them to user
- re-read the data from storage while listening to a event listener (the event emits from an another file after data gets updated and stored on local storage)
I know a few things about FutureBuilder()
in flutter and using it to fetch the data and then display them but I was wondering how to achieve this functionality in Flutter.