Flutter Community

Articles and Stories from the Flutter Community

Follow publication

Flutter cache with hive

--

Recently when I want to get data from online I used Rest API and fetched the data from it,but the problem is every time it’s need healthy internet connection.And the thing is I can’t access it when I’m offline. So there I thought of using cache concept and save it in local storage.And so that data could be accessed without internet connection.

Libraries

In order to cache let’s go by step to step

Step➊ : Create model

Then after this run a command in teminal for building model_name.g.dart

flutter pub run build_runner build

Step ➋: Write services

Lets create API service in order to fetch data from online and decode it into JSON format

Now lets move on to next step for caching in this project we are using hive to cache data and lets write service for storing data into hive and retrieving data from hive

That’s it now lets use this service in view model

Step ➌: Now lets call this method

By using this services we can cache the rest api data

In my opinion hive is better for storing data in local and it is fast compared to shared preferences,Moore,sqflite.

For more details check this github repo:

https://www.twitter.com/FlutterComm

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Flutter Community
Flutter Community

Published in Flutter Community

Articles and Stories from the Flutter Community

Shashiben
Shashiben

Written by Shashiben

Experienced full stack developer who care deeply about building interfaces that are usable and pleasant for the most number of people.

Responses (2)

Write a response