How can I refresh an individual List Tile in a Listview.builder? Flutter - firebase

Situation:
I have an 'Event' item that you can click on --> Event detail screen.
That has individual subitems (date,participants,description) in the form of a list.
I load the subitems with a Future Builder into a Listview.builder with a List Tile like so:
I have a button to edit the location, it saves to the database and locally updates the location variable. This calls SetState().
The full list is updated, even if some tiles don't have changes.
THE PROBLEM
Some tiles, like the participants tile needs to load pictures and some other things that are time intensive. So even if I just change the location and update the list, everything reloads, consuming resources and taking too much time to load a simple string.
WHAT I AM LOOKING FOR
Is it possible to reload only a certain list tile? Would you use another widget instead of ListView.builder? Other logic? Any help is appreciated.
Answer Extension [Update]
The marked answer is correct. I was using future builder and that was forcing me to reload all data always. By using different Streams with Streambuilder I am able to change data on database and it automatically changes on the UI, without updating the state! Magic.

base on what i notices, Future Builder is the problem, Future builder rebuild the whole widget in the ListView.builder. in your case use StreamBuilder and you see the changes you what...

Related

Is it possible to do paging (numbered) with firebase?

I started a project with firebase. Everything was perfect until it came to the paging section. But I was disappointed about paging. Please help me. Now I will write what I want to do.
There are 100 posts. I'll show 25 on each page.so this means 4 pages.When the user wants to move to the fourth page while on the first page, I want the data of the second and third pages not to be downloaded, only the data of the fourth page to be downloaded. one more example. when the user goes to "https://example.com/posts/page-3" I only want the posts on the third page to be fetched.
Is it possible to do this?
Your question does not specify if you are using Realtime Database or Firestore, but the answer is the same for both of them - it's not possible to do pagination using numeric offsets. In order to request a page of data that starts anywhere after the first item, you are required to know something about that item, or the one that comes right before it. If you don't know anything about that item, you have to start from the beginning, then work you way forward. That's how cursor-based pagination works.
With Firestore pagination, this why the API requires you to pass a DocumentSnapshot to start from, or field values from that document.

Flutter/Dart/Firebase - Reduce unnecessary data loading

I tried searching my specific problem but I could not find any suitable solution.
I would like to thank everybody in advance for your help.
I am currently developing an iOS app.
The App represents a user profile which can be updated by the user.
Everything from the authentication, registration and the possibility to update your user data works fine with the help of Firebase. Now I would like to optimize some code.
So the application has 2 Screens, HomeScreen and EditScreen.
(Besides the Screens needed for registration and login).
To keep my question short:
How can I reduce the amount of data which is loaded from firebase?
Example:
1. User is on the HomeScreen, to build the view his image loads from Firebase Storage
2. He wants to edit his Image and therefore switches to the Editscreen, where his image will be loaded again
3. After changing his image, the new image will be uploaded to Firebase Storage and he can see his new image on the Editscreen
4. If he now switches back to the HomeScreen his new image will be loaded again from Firebase
Is there a good way to reduce the amount of loading?
Like caching the image between step 1 and 2?
As there is always a little delay in displaying his image.
Thanks!
Sadly I am not allowed to share any code.
You can check out the flutter_advanced_networkimage package. It will cache your photo upon load. For everything else, you should just move your profile object (or whatever it is that calls for the firebase user's information) above those routes and pass it down through your widget tree through arguments or state management.

Delay Meteor subscribe until more resources are available

I have subscriptions users and product which give about 5000 and 7000 docs respectively. I use the data for typeahead searching in users and product forms. If we subscribe on form render, then the form takes too long to load so we subscribe on Meteor.startup, but that also makes our startup time slow.
How can we make the subscriptions run after the first screen is finished loading without touching the code for the first screen? I don't wanna do subscribe inside firstScreen.onRender() because there can be multiple first screens depending on the url entered.
I tried doing Meter.defer in Meteor.onStartup but that didn't work.
Alternatively, is there a better way to accomplish typeahead with semantic beyond loading all the data?
Any ideas?
I strong recommend you to use the Pattern 'Template-Level Subscriptions' to make sure that you have your data ready to your templates.
Here is the link that explain this -> https://www.discovermeteor.com/blog/template-level-subscriptions/
I hope that helps,

Different URL paths in different tabs depending on id

Let's say a user has a list of projects, and each project has it's own set of various collection items of charts, reports, tags, etc associated by project._id
When a user selects a project, all the associated collection items are viewable by route, for example /project/<projectId>/chart/<chartId>
Currently, a user can only view one project at a time. If he opens up a new tab or a new browser, he can still only view the one project. If he switches the project, all the other tabs/windows reactively change to the new project. This is because currently the project is tied to Meteor.user.profile.projectId (but I am looking for a better way).
I would like to change this behaviour so that tabs and windows are independent of each other. If a user pastes project\project1 into a new window it should load that and it's associated collections even if his current tab is in project\project2. I hope that makes sense.
I'm not sure how to accomplish this. I am looking for suggestions and solutions. Thanks.
I believe that this can easily be accomplished using session variables:
set a default somewhere in your client code, Session.setDefault('project', 1) (or make sure that project being undefined is handled gracefully)
when a user selects a project, set the variable:
Session.set('project', [selectedProjectId])
Wherever you need to decide which project to show: Session.get('project')

Architecture question involving search & session state

I have a grid with several thousand rows that can be filtered and sorted. On each row you can click a details button, which will bring you a new page with detailed information about the page. Because this is a button, you can't middle click or right click and open in a new tab. In addition, when clicking back you lose your filters and search results.
To solve this problem, I considered the following: Switch the buttons to links, and when filtering and searching, use get instead of post requests. This way, you could switch to new pages with a right click or middle click, and if you did follow a link normally, back would work properly.
This change was not made however. We were asked add a 'next result / previous result' set of buttons on the details page, that would allow you to navigate. While not an elegant solution, it would at least work.
I proposed adding querystring parameters to the details page, that would regenerate the search query based on filter, and allow you to get the next and previous results in code.
A team member took issue with this solution. He believes that it is a waste of server resources to re-query the database. Instead, a solution was proposed to add session variable that included a list of results. You could then use that to navigate.
I took issue with that because you can't have multiple tabs open without breaking navigation, and new results aren't appended to the list in real time. Also, if you worried about optimization, session would be the last thing to use since it eats memory and prevents server replication... unless you store the results back in the database.
What's the best solution?
Session doesn't sound like a winner, won't scale with lots of users.
Hitting the database repeatedly does seem unnecessary, but it depends on the cost - how many users, how often would they refresh/filter and what is the cost of that query?
If you do use querystrings you could cache the pages by parameter.
What about some AJAX code on that button to retrieve details - leave the underlying grid in place and display details in a div/panel or a new window/tab.

Resources