flutter - 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
解决方案
您需要在 0 索引处添加项目,因此使用List.insert
方法。
setState(() {
yourList.insert(0, yourItem);
});
List.add()
是的,和之间有区别List.insert()
,前者将项目添加到列表的末尾,然后允许您将项目添加到某个指定的索引处。
推荐阅读
- r - 如何在 dplyr mutate 函数中使用 data.frame 列值作为函数参数
- macos - Visual Studio Mac,从命令行构建?
- amazon-web-services - 上传到 S3 时的 EntityTooSmall
- javascript - 如何在 ng-repeat 中为多个 Select 填充动态选项
- python-3.x - GUI 应用程序在启动套接字服务器时停止
- python - 如何识别 Django 中 NoReverseMatch 错误的来源?
- c++ - 访问冲突抛出异常:写访问冲突。window.vertexBuffer 为 0x1110112
- django - 通过外键查询数据库
- git - Git将更改从一个远程推送到另一个
- spring-boot - 关于 Spring Data Flow Server 的困惑