如何在ListView中滚动项目以便可见? [英] How to scroll item in ListView so it is visible?

查看:44
本文介绍了如何在ListView中滚动项目以便可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将新项目(例如ListTile)添加到ListView时,是否可以将新添加的项目滚动到视图中?新项目可能不在列表的底部(例如,按字母顺序排序).

When adding new items (e.g. a ListTile) to a ListView is there a way to scroll the newly added item into view? The new item may not be at the bottom of the list (e.g. it is sorted alphabetically).

推荐答案

您可以使用ListView. html"rel =" nofollow noreferrer> ScrollController .

You can scroll through a ListView using a ScrollController.

final scrollController = ScrollController();

// ...
ListView(controller: scrollController // ...
);
// ...
scrollController.animateTo(height, duration: Duration(milliseconds: 678), 
  curve: Curves.ease);

您将必须自己确定高度.可以使用商品的索引和商品的总高度来完成.

You will have to determine the height yourself. That could be done using the index of your item and the general item height.

这里有一个完整示例.

这篇关于如何在ListView中滚动项目以便可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆