Let's say I have millions of records like this. I am showing this information in GridView. It will take a lot of time to download the whole database and then display results. How do I download only 50 records at a time and when I am about to reach the end of list download another 50 and so on like Google image search results? Is it possible?
What you want is called pagination. I don't know about real-time databases but I do know firebase firestore provides you with tools to do that. You could check this link out for firebase firestore.
https://www.youtube.com/watch?v=poqTHxtDXwU&feature=emb_logo
You can write code to fetch specific data then add a scrollController to page and a code to fetch next data whenever your scrollController reaches bottom of page.
For it you have to learn using scrollController.
https://youtu.be/pGmHYXC5MeU
Related
I have two screens:
Homefeed.dart
Profile.dart
On Homefeed screen all the data from various users is fetched from a server and is shown in a list of cards form.
On the Profile screen, only data that belongs to the logged in user is fetched.
The problem is that, there will be an overlap in the data that is fetched on the both the screens. For example if a user writes a post, it can show up on the Homefeed. Now if the user decides to perform any action such as like, delete, edit etc on thir post from the profile screen, then it should also update the same post that was fetched on the Homefeed screen.
Now unless user explictly refreshes the data, and send a request to server to fetch the updated data, what would be an ideal way to achieve this synchrony.
I did consider using a realtime database, but this will mean migrating current project and it might get expensive and might have problem of it own.
The other "hacky" way would be to maniuplate data somehow (I still havent figured it out) on the client side and show the update instead of fething new data from the server.
Or some other, more ideal way of achiving this, that I don't know of.
The best way is to reflect any changes of the user post i.e edit, delete in Profile.dart is by updating the database without tricking the just in the client side. Because you may reduce the database calls by tricking, but you are giving high chances of inconsistent data in database. Your database wouldn't be reliable.
Database should be the single source of truth
I would suggest, Every time HomeFeed.dart page is loaded , try loading the latest data from the database. If you are using real-time database, you dont have to check on every page load.
I want to plot bar charts to show live data fetched from webpage.
I have managed to get response from webpage in json format then convert it to List and plot the data, but it doesn't get refreshed.
There are 3 ways to achieve this.
Make self-calling a future method that calls itself until the screen is disposed of.
Create socket and listeners every time update data. You can listen to change and update the pie chart. Same as a real-time chat application.
You can use firebase's real-time database for this solution.Every time data update in schema,Application will state recalls via streams automatically
When using StreamBuilder in Flutter to read changes in a document in Firestore, how am I charged?
Am I charged for each time I listen whether there is any change or not multiplied by number of users or any different pricing is used.
After doing some research and reading documentation, I am ready to answer my own question.
If we are using StreamBuilder to fetch Snapshot from Firestore then we are charged for read only when the data is updated and are NOT charged continuously.
Hope it helps someone else.
I have a document in Cloud firestore to which I listen for updates. It has 2 fields, it has a field description and a field for a picture. The picture is approximately 0.2 mb and description is a few words. I wanted to know what would happen if I made changes to the description in the document, I wanted to know if addSnapshotListener actually downloads a fresh new copy of the document or just the field that has been changed.
I indeed see, by looking at how much data is being downloaded in Xcode, a new fresh copy of the document is downloaded.
This is not efficient at all, since the picture field is rarely changed, only the description might change in my application.
Is there a way to optimize this?
Is there a way to optimize this?
Yes! Don't do that.
Firestore (and the realtime database) is not intended to store images or large datasets per field.
You should explore Storage and keep a reference (url) to the item stored in storage in your Firebase.
Cloud Storage is built for app developers who need to store and serve
user-generated content, such as photos or videos.
By leveraging storage if you need to update or change a field in Firestore, you're only working with a small amount of data instead of an entire image worth.
To answer the question; if you read a document from Firebase, it does read the Document and it's child data.
Here's a link to the Storage Docs which shows how to capture a reference to the item uploaded to storage.
https://firebase.google.com/docs/storage/ios/upload-files
If you want to automatically sync the images to all clients and have them available offline, just put them in a separate document.
// Store your small, frequently changing text here:
db.collection('users').doc(userId).set({email: vince#example.com})
// Store your image here:
db.collection('user_profile_pic').doc(userId).set({data: <imagedata>})
i want a make a feed reader...i want load politics news from multiple data dource in one tableview synchronously.
what do i do?
i went to this link: table view with multiple data sources/nibs
but this solution is not synchronously
So basically what should be the approach when we have multiple data source but single instance of table view to show the data?
What I would do is to create a backend service where the news are merged into one list. This allows you to easily edit the algorithm without the user having to update the app. And your backend also only have to crawl the websites once instead of every client having to do it every time a user wants to see the news.
When you fetch data from that service it will come in one list, and you already know how to do that :)
It shouldn't be synchronously, because you wait for the rss response.
You better show a spinner and reload the tableview data once you collect all the responses.