首页 > 解决方案 > How to show recent items first?

问题描述

I've a long list that holds some data, and whenever i add a new item to the list, the item added to the "end of the line".

How do i show the last added item first?

Something like show recent items first

标签: flutterdart

解决方案


您需要在 0 索引处添加项目,因此使用List.insert方法。

setState(() {
  yourList.insert(0, yourItem);
});

List.add()是的,和之间有区别List.insert(),前者将项目添加到列表的末尾,然后允许您将项目添加到某个指定的索引处。


推荐阅读