Home > Back-end >  How to cache api calls response data for sometime in flutter application?
How to cache api calls response data for sometime in flutter application?

Time:07-24

In a flutter app, is it possible that we can cache api calls response for some time? Its a nuisance from user point of view that whenever I change tabs, I see nothing is avilable although there is: https://imgur.com/mWeYnV5

I have 3 tabs offer availables , collected offers , offers I have posted..... It takes some time to load data everytime the tab is changed. Can I do something about it?

A little piece of code

child: isdataNull
          ? Center(
              child: Column(
                children: [
                  SizedBox(
                    height: MediaQuery.of(context).size.height * .25,
                  ),
                  Container(
                    height: 120,
                    width: 120,
                    decoration: const BoxDecoration(
                        // shape: BoxShape.circle,
                        //border: Border.all(width: 1),
                        image: DecorationImage(
                            image: AssetImage('assets/nocollection.png'),
                            fit: BoxFit.fill)),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  const Text(
                    'No offer available',
                    style: TextStyle(color: Colors.black, fontSize: 14),
                  )
                ],
              ),
            )
: FutureBuilder()

I make a Grid in future builder Is there any solution to this?

CodePudding user response:

you can store the response of api in shared_preferences and check when have shared_preferences result do not call api and read the shared_preferences data

CodePudding user response:

You can store Your data into getstorage if you have small amount of data. if you have big data like sqllite database then you have to use sqlflite database to store it.

  • Related