简体   繁体   中英

How to cache phone contacts in flutter?

I am starting to learn flutter and was creating a contact management application.

I am using the 'contacts_service' package to get phone contacts on app load.

This return a

Future<Iterable<Contact>>

where Contact is defined in contacts_service.dart.

Contact has a toMap and fromMap function.

Calling the ContactsService.getContacts(); on every app load causes the app to load slowly. I was wondering what is to best way to cache this data. Cache manager packages are all aimed at http calls (atleast I couldn't find one for this). I tried to write manually to the temp folder. I am stuck at how to store the List in the file. Any help is appreciated.

You can use database sqflite .

Or use key-value database hive for which is fast.

var contactBox = await Hive.openBox("contact");
await contactBox.addAll(contacts);
``

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM