Flutter: A way to append incoming data to ListView instead of rebuilding entire thing? - flutter

Summary: Planning to show readonly data array in a ListView widget. Data comes in using a Provider. Is it possible to not rebuild the entire ListView every time, and just append a new Tile to it?
Details: The ListView data set coming in is similar to log entries--it's static and only the last item is coming in. Rebuilding the entire ListView every time seems a bit wasteful. Is it possible to have it in such a way that it would append new Tile widgets on incoming data instead?

Please provide some sample code or your code. For now from this question I'll suggest you to take a look on AnimatedList.

Related

Refreshing only those rows DataTable or ListView that are affected by changes in Flutter

I have a DataTable (or ListView) and use bloc pattern, for example, for state management. Each row has an action which deletes it. Deletion should be done first on the server and I wish to update DataTable to only remove this row by not refreshing the whole DataTable (or ListView). All I can do right now is to only refresh the whole DataTable, which destroys UX.
What would be the best approach?
ALso, it would be acceptable too if anyone can recommend a plugin that solves this problem.

How to call setState() during integration tests?

Hi, there!
I testing screen which contains GridView with items inside. The GridView is built dynamically based on the data stored in the database. Then in tests I manually add one item to database, after that I want to call setState() for showing and checking it. But I have no idea how to do that. Is it real?
Thank you in advance!
I think you don't need to use setState() in this case. Use StreamBuilder to show GridView based on data from firebase. Here's a video of how to implement it https://www.youtube.com/watch?v=MkKEWHfy99Y

How to prevent Stateful Widget stored in List to be disposed?

Let me start by explaining the problem. I have several buttons which are created based on data I'm getting from a server. On each button click I need to create and display a widget which will present me some data (this widget is also built dynamically). The state of this widget has to be preserved during the lifetime of the app. (for example if I click another button and show a different widget, I need to be able to click on the first button and show the first widget in its preserved state). Number of buttons can also be changed during the app lifetime.
I tried using IndexedStack to achieve this, but when the number of buttons is changed I need to add "pages" to IndexedStack, therefore I need to recreate a new IndexedStack which will have some of my old widgets, so I pull widgets from a List or create new ones if needed. This works great, except Flutter calls dispose() method on my widgets which are stored in the list. I tried using the AutomaticKeepAliveClientMixIn but it didn't help.
I'm guessing this has something to do that the widgets get detached from the parent, but when I reattach them to new parent (new Indexed stack) Flutter doesn't figure out this properly.
Any ideas?
Try to store data to local storage or sqlite for persistence data.

How do I save widgets that belong to a page and dynamically render them in the future?

So, I need to build custom pages with custom widgets in Flutter, save these pages in memory and recall the custom widgets and their children in the future.
Saving variables is not a problem, as you can use sqlite or json or firebase.
But how can you save an entire page in Flutter??
How can I achieve this?
Please help!

What's the alternative to using a StreamBuilder inside of a column or row?

I am trying to build a page that shows a hierarchy of data. The top of the page is built by passed in data. But the dependencies need to query a db and post their results.
For example Team A has players. Under the heading of team A I want to show a list of players on the team. But if I try to add a streamBuilder as a part of screen, I get all sorts of nasty message about some part of the build process not having a height. Its seems that streamBuilder only works as the highest level widget.
So there must be an alternative for building those widgets, can anyone point me to an example of that being used?
An alternative to a StreamBuilder is FutureBuilder - where you can use a Future callback instead of a Stream to fetch a data snapshot for the children Widgets inside it.
However, if you're getting "unbounded height" errors, this is usually thrown by children Widgets with undefined height inside a ListView or Scrollable widget. You'll be needing to set a height for those List items to fix that error.