I am facing an issue, There is one screen where I am calling an API and getting data but when I go on any other screen to do some work and when I come back to the home screen (main screen where I am calling API) It again call for an API and I am using loader till data is getting fetched from API. So it feels frustrating when it always calls an API.
Is there any feature or anything that I can use to keep my fetched as it is until I close my app in flutter?
Here is a video of an issue that I am facing, every time I come on the dashboard It calls an API to fetch that image, is there any way that I can keep this image here permanently because this image is going to change on daily basis?
You can use shared_preferences to save your data locally after API call. then you can use these data whenever you go back to the screen.
Future addSharePref() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('storingName', yourVarName);
}
Then when you open the screen again you can just call these values from shared_preferences. something like this:
yourVarName= preferences.getString('storingName')?? "No name found";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With