I wanted to reverse list and I have achieved this by using reverse: true,
. It is working, but the list has aligned to the bottom and showing blank space at the top when the list has least items.
Expanded(child: ListView.builder(
shrinkWrap: true,
reverse: true,
controller: _scrollController,
itemCount:order_response.orderDetails.length,
itemBuilder: (context, position) {return orderListItemTile(width,height,order_response,position);},
),)
But when I deleted expanded()
widget, when items increase then it overflows by pixel.
ListView.builder(
shrinkWrap: true,
reverse: true,
controller: _scrollController,
itemCount:order_response.orderDetails.length,
itemBuilder: (context, position) {return orderListItemTile(width,height,order_response,position);},
),
Apart from reversing the list, another solution could be putting the ListView
inside an Align
widget with alignment: Alignment.topCenter
. Also shrinkWrap: true
needed inside ListView
.
Align(
alignment: Alignment.topCenter,
child: ListView.builder(
reverse: true,
shrinkWrap: true,
...
...
)
)
使用以下方法反转您的列表:
var reversedList = _response.orderDetails.reversed.toList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.