Scroll Parent ListView when nested ListView.builder is updated - flutter

I have a ListView with, say, PostItems being generated with ListView.builder.
Each PostItem MAY have comments on it. So each PostItem has a nested ListView.builder to show comments for that PostItem.
User can add a Comment to the nested ListView. However, UX would like to scroll to that newly added Comment in the nested ListView. Nested Listview shrinkwrap is true, with NeverScrollable Physics. When nested Comment listview expandeds with new Comment, it's off screen and I want to scroll down to it.
ListView.builder -> PostItem -> Nested ListView.builder
However, my assumption is that I need to make the parent ListView scroll down but how do I know where to scroll to when it's the Nested listview that has grown in height.
I can't share code due to the project but any theological thoughts or ideas would be a great help!
Thanks

I can see that, based on your description, we can access the index of that particular ListView. Thus, I would suggest you to use this package to achieve what you want:
scroll_to_index

Related

Scroll within a swiper page

I have a swiper page in flutter where I have some textformfields as column children. Now when I focus on the last textfield. The textfield gets covered by keyboard. I would like to make the column scrollable so I put the column as child of singlechildscrollview. But since the page is already part of a swiper page and hence scrollable. The scroll is not working for the column. How do I go about implementing this?
Add physics: ClampingScrollPhysics() property for SingleChildScrollView. May be this will solve your problem.

Difference between ListView.builder vs manual list?

I can also create lists by this code that I can with ListView.builder so what differentiate both?
for(Item in List) View(Item);
I am new to development and trying to understand this.
Is it good if I use above approach?
When items are limited(not more but few) you can use ListView widget, but for many items (like as thousands of items, also created on demand) - You should use ListView.builder.
The difference between of them is: When you use ListView, all the items are rendered on screen. But when you use ListView.builder, items are rendered on demand. Only the items are visible on the screen and few of above & bottom are rendered.
For more:
ListView
ListView.builder

Unwanted animation while scrolling down the ListView.builder in Flutter

I have listview.builder widget which have several ListView.builder and GridView.count with scrollDirection:Axis.horizontal inside of it. All the data comes from the services and I am using FutureBuilder to fetch them. My problem is whenever I scroll the main ListView.builder,other listview items comes with animation(items comes from left, from right). Specially if I scroll fast. I didn't use any animation, and I don't have any idea about the problem, maybe its rebuilding everytime I scroll the lisview, but I am using AutomaticKeepAliveClientMixin for main ListView. Do you have any idea? Thanks for reading.
This question might be duplicate, I solved my problem using this answer: https://stackoverflow.com/a/57984979/10025471
The problem is everytime I scroll the listview, it's children rebuilding again and again. So I convert to stateful widget all of the children and I added AutomaticKeepAliveClientMixin to all of them. Now, there is no unwanted animation, and redundant rebuild

In which circumstances should you use listview instead of listview.builder?

Like the topic I was wondering of there are any circumstances one should use the regular ListView instead of the ListView.builder in flutter, like if there are few items in a list could the ListView give better performance?
ListView has actually four different ways to use it , But let discuss ListView and ListView.builder
ListView : It has a children
property that takes a collection of static widgets. A ListView takes a small number of other widgets and makes it scrollable. Why a “small number”? Because this is designed to be a static list, one that you, the developer, simply types into the build() method
by hand.
ListView.builder : ListView’s alternative constructor, ListView.builder receives two
parameters, an itemCount and an ItemBuilder property that is a
function. This makes the ListView lazy-loaded. The itemBuilder function
dynamically creates children widgets on demand. As the user scrolls close
to the bottom of the list, itemBuilder creates new items to be scrolled into
view. And when we scroll something far enough off the screen, it is paged
out of memory and disposed of. Pretty cool.
Reference : taken from Rap Payne's Beginning App Development with Flutter (Great Book for beginners! , not an affiliate link).
official documentation for ListView .
ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. So if you just want to show some widgets below earch other and you need to scroll them you use ListView.
ListView.builder is a way of constructing the list where children’s (Widgets) are built on demand. However, instead of returning a static widget, it calls a function which can be called multiple times (based on itemCount ) and it’s possible to return different widget at each call.
I guess the simple answer you were looking for is:
Use ListView.builder whenever you iterate over an array of 'similar' elements.
Use ListView when items in your list are completely different from one another.
Think of ListView as scrollable Column

Is there any deafult widget like in image or if I need to do it how could that be implemented?

So I am not looking for filters but I am looking for scroll widget. I have tried generating listview items abd getting position of listview to give items ratio but I wasn't able to get any functionality while in certain index position. Any help would be helpfull. Naming of the widget or special widgets that can make me do this etc.
You can use ListView or ListView.builder to do that, but with circle-shaped widgets as the children.
You can check out this tutorial to do the horizontal list. And you can check out this StackOverflow question, to create a circle button. Or instead of a button, you want to use the CircleAvatar (to add an image in it), you can check out this official doc.