Flutter Firestore Cache with Hive
Budget: $30 – $250 USD
LOCAL DATA CACHE
1. Create a Firestore collection. Documents can have some simple dummy data like;
-UID
-name
-image
-lastUpdated (a full date)
-array (contains 10 to 40 keywords or IDs from a pre defined list) Define a dummy keyword / ID list and put some of them to each document. Random dummy data. Nothing fancy.
2. Create a flutter app, show an empty loading page with a simple loader.
3. Create a date limited (as you don't have a local lastChecked date at that moment use an earlier date) and array-contains query. (query just one keyword / ID from the mentioned array field). Load the results in a Hive box with document UIDs.
4. Show results in a listview from Hive (data comes from Hive first and query firestore for updated documents with date limit as mentioned above) Also Update listview items if there are new objects or updated objects.
5. Keep a local lastChecked date. Use this for future queries.
(Query firestore with lastChecked date to filter lastUpdated data. Get the updated documents. Add new documents to hive if there are any or update old ones if their lastUpdated field is newer then the last checked. )
IMPORTANt: Local HIVE query is also based on the keyword that is in the array filed mentioned above.
6. Show user a list of keywords / IDs so the query can be changed based on keyword. (Can be search box or a dropdown list no problem, UI is not important at all)
PS. If there are no updated or new documents in the collection firestore query should have no results. So no updates happen for local Hive data.
IMAGE CACHE
1. You don't have to code a custom image cache system. You can use any available flutter package like; cached_network_image or your choice of image caching packages.
1. Create a Firestore collection. Documents can have some simple dummy data like;
-UID
-name
-image
-lastUpdated (a full date)
-array (contains 10 to 40 keywords or IDs from a pre defined list) Define a dummy keyword / ID list and put some of them to each document. Random dummy data. Nothing fancy.
2. Create a flutter app, show an empty loading page with a simple loader.
3. Create a date limited (as you don't have a local lastChecked date at that moment use an earlier date) and array-contains query. (query just one keyword / ID from the mentioned array field). Load the results in a Hive box with document UIDs.
4. Show results in a listview from Hive (data comes from Hive first and query firestore for updated documents with date limit as mentioned above) Also Update listview items if there are new objects or updated objects.
5. Keep a local lastChecked date. Use this for future queries.
(Query firestore with lastChecked date to filter lastUpdated data. Get the updated documents. Add new documents to hive if there are any or update old ones if their lastUpdated field is newer then the last checked. )
IMPORTANt: Local HIVE query is also based on the keyword that is in the array filed mentioned above.
6. Show user a list of keywords / IDs so the query can be changed based on keyword. (Can be search box or a dropdown list no problem, UI is not important at all)
PS. If there are no updated or new documents in the collection firestore query should have no results. So no updates happen for local Hive data.
IMAGE CACHE
1. You don't have to code a custom image cache system. You can use any available flutter package like; cached_network_image or your choice of image caching packages.