Increase/decrease item count on scroll up/down in Listview builder whose items have variable size(height) - flutter

I am trying to display the item number in a separate widget. I am using Listview builder whose child(itemBuilder's return statement) is a card. The height of the card is not constant. It keeps changing depending on the length of the data, the card is displaying.
I found this => How to display scrolling index for scrollController in flutter? . But in this solution, the card has a fixed size(height). Can somebody suggest what should be done if the card is of variable height.

Related

SingleChildScrollView clips height of column in "drag_and_drop_lists" plugin

I'm using the "drag_and_drop_lists" plugin to move around ListTile items in a column in a Flutter app (latest version of Flutter) on Android. My problem: ListTile items with a long subtitle value get clipped in height. In the example below, there's text in a line below after "key from & drop off" that I can't see:
The widget on this screen is a DragAndDropLists. "1", "2", and "3" are the DragAndDropList in it.
Here's what the ListTile looks like - it has a height of 184 pixels:
The plugin wraps my ListTile in a number of widgets. The last one with a height of 184 pixels is the column:
That Column is in a SingleChildScrollView. And that's the first one with the wrong height — 145 pixels:
Here's the line in the source code creating that SingleChildScrollView. If I remove the physics: NeverScrollableScrollPhysics() attribute there, I can scroll my ListTile. Here, the title is now missing, but the whole subtitle is then visible:
I don't know how to get the SingleChildScrollView to show my Column at full height. I tried a number of things but nothing worked. I didn't file a GitHub issue with the plugin, as the plugin author hasn't responded to an issue for quite a while.
I couldn't fix this with a regular ListTile. So instead, I now show a separate Text widget with the text. And that doesn't get clipped.

Put ListView in/out of Expanded based on how big the ListView is going to be

I have a ListView that might be big / small, depends on result of API call. What I want to do is if the result is too big, put this ListView inside Expanded.
The client could be anything, phone or tab, all with different sizes, both horizontal and vertical orientation supported.
How do I detect the size of the ListView before it gets built?
if (MyListView.height > this.container.height) { // ListView isn't built yet, so how can I know the size?
return Expanded(child: MyListView);
}
return MyListView();
// MyListView is just a ListView inside a Container
API calls should be made inside initState function so that you don't hit the endpoint with each rebuild. (which can happen many times) You can create an empty future object in your statefull widget and in the initState function assign your api call to the future object. In build method add a FutureBuilder widget to control the state of the api call. (loading, errors? etc.) Once you get the data just check the length of the list and depending on that you can decide what to do:
data.length < 20 ? MyListView() : Expanded (child: MyListView())

How to get the size of children widget when the `build` method are called in Flutter?

I have a view which include an scroll animation are called BubbleTabBar. Have a list of children widget inside my BubbleTabBar. I want to detect the size of all children inside BubbleTabBar for enable/disable scroll. However, I only get the parent size by LayoutBuilder. Now, I have to force user input only list of text to my widget and calculate the size by RenderParagraph. I wonder that have any way to calculate the size of widget at build time? Use global key to get render instance are not working for me.
TL;DR:
I wonder that have any way to calculate the size of widget at build time?
Demo source code here (Please change the size of preview panel):
https://dartpad.dev/embed-flutter.html?theme=dark&id=6f6a5fc73803bdfaf2a493a35c258fee

Resize List row in SwiftUI

I have a List and each row in the list has a .tapAction that toggle's it's collapsed state property. When collapsed is false, the row is expanded and displays more detailed information.
The problem I'm having is that when a row is expanded, the view inside the row changes it's height but the row remains the same height. This causes the row's contents to sometimes expand outside of the row.
Is anyone else having this issue? Is there another way of resizing a row besides resizing it's contents?

android listview getselectedItem returns null

I have a listview and a button outside listview. I want the user to select an item in listview and then when clicking on button I wanna get the selected item of list view. I have set choiceMode to single choice on listview, but when I try getselecteditem it returns null. How should I get the selected Item?
thanks.
This is an old question, so probably not that relevant anymore. But here's what's the problem:
The ListView doesn't store selected item position when you just set the choice mode. It stores the checked item position.
In short, you would use something like:
int pos = listView.getCheckedItemPosition();
myObject = (MyObject) listView.getAdapter().getItem(pos);