Is it possible to use ReorderableListView in a "wrapping" mode? - flutter

I would like the ReorderableListView not to take up the whole height which is given to it, but to be as tall as the item views that it contains.
I could make the list either flex and fill the whole height it is given, or put it in a SizedBox and have a fixed height.
I'd like to add an + Add list tile directly under the list items (similar to Google Keep on Android)
Thank you

You can try this:
Wrap your List with an Expanded widget.
Fetch the number of items in your list and return the Add List tile widget at the length-1 position of your list.
You can alter the size of your ListView in correlation to the number of items fetched from the list.
Expanded will help you alter the length dynamically.
eg:
Expanded(
child: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int Index) {
return new Text(litems[Index]);
if(length==length-1){
//**call your Add List tile widget here**
}
}
)
)

Related

How can I add pages to a flutter listview builder?

Instead of infinite scrolling in a Listview.builder.
I want to be able to see x amount of items in my ListView and then going on to the next page should show the next x amount of items.
What I have so far is just a standard ListView.builder:
Listview.Builder(
itemCount: data.length
itemBuilder:(context, index){
return Card(
child: ListTile(
title: data[index]
)
);
}
)
You can use a PageController to control which page is visible in the view. In addition to being able to control the pixel offset of the content inside the PageView, a PageController also lets you control the offset in terms of pages, which are increments of the viewport size.
The PageController can also be used to control the PageController.initialPage, which determines which page is shown when the PageView is first constructed, and the PageController.viewportFraction, which determines the size of the pages as a fraction of the viewport size.
Refer to :
geeksforgeeks
Flutter Docs
Hope this helps. Happy Coding :)

Flutter scroll controller infinite scroll fail on larger screen size

I have a problem with infinite scroll in flutter, I am loading six items per page and loading more as I scroll , this works perfectly with a smaller screen size but the problem comes in when I use an emulator with a larger screen size, when the screen size is larger then the first six items don't fill the screen hence I cannot scroll in order to load the other items.
Does anybody have an idea of how I can get around this?
Thanks
You can use ListView.builder. The ListView.builder constructor takes an IndexedWidgetBuilder, which builds the children on demand. This constructor is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.
return ListView.builder(
padding: const EdgeInsets.all(10.0),
itemBuilder: (context, i) {
if (i.isOdd) return const Divider();
final index = i ~/ 2;
if (index >= _listItems.length) {
_listItems.addAll(_newItems); //load more items here
}
return yourWidget(_listItems[index]);
},
);
This way no need to use scrollController. You can refer to this codelab for more info.

Making parent adjust to size of child widget

I am using a ListView Builder, and that has to be wrapped inside a Container. If i don't give a height parameter then i get Vertical viewport was given unbounded height. Now, because of this if i only have 1 item in the list, any content comes after the container, which wastes a lot of screen real estate and doesn't look aesthetically pleasing.
How can i make the parent widget i.e Container() to adjust to the size of child widget ListView.builder() ?
Add this shrinkWrap: true to your ListView and Remove Height from container.
snippet code:
return Container(
child: ListView.builder(itemBuilder: (context, index) {
return listItem(itemArray[index]),
},
itemCount: itemArray.length,
shrinkWrap: true),
);

How i can make like this widget, in which when data grow up the last two item come down automatic

How can I make like this widget, in which when data grow up the last two item come down automatic and the size increase.
I don't want to use a fixed size
You are correct, you should not use a fixed size. You need to use a ListView
Assuming your items are in a List (e.g. of String to keep it simple):
List myInvoice = [];
myInvoice.add("Haircut Fee");
myInvoice.add("Beard Shave Fee");
//...
myInvoice.add("Tax");
Then, display in a ListView
ListView.builder(
itemCount: myInvoice.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(leading: myInvoice[index]);
}
);
If you get the logic, you can modify the List to hold objects more complex than a String, or use two lists.
More here

How do i monitor which ListView item is selected in Flutter?

In my listView i have the itemBuilder value set to a custom widget
Widget programsRowWidget(BuildContext context, List<MembershipPrograms> programs) {
return Expanded(
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: programs.length,
itemBuilder: (context, index) {
return UsersProgramListItem(program: programs[index]);
}
),
);
In that widget the root element is a Card, whose child is an InkWell. I want to use it's onTap property to control if the item is selected or not. How do i monitor which item in the listView is selected from the listView in the parent widget shown above, and how do i allow only one item to be selected?
How do i monitor which item in the listView is selected from the listView in the parent widget shown above
You can use bool flags such as isSelected and isSelectable, which is passed to a widget in a builder function. The main aspect there is to separate logic of selection from ListView.builder to upper widget or to object of your element.
How do i allow only one item to be selected?
Use flags. When one item is selected - the flag of selectable for others can be set to false.