android - Flutter ListView没有滚动到最后一个添加的项目,而是最后一个之前的项目
问题描述
我在我的类中使用 aListView.builder
将动态内容添加到列表中。我使用控制器来保持底部焦点controller.jumpTo(controller.position.maxScrollExtent);
但我不知道为什么,它不关注最后一项,而是最后一项之前的一项......
这是我将项目添加到列表中的功能
if(numTeam == 1){
_listAnnonceTeam1.add(nbrPoints);
_controllerAnnonceT1.jumpTo(_controllerAnnonceT1.position.maxScrollExtent);
}
这是我的 ListView.builder :
child: ListView.builder(
controller: _controllerAnnonceT2,
itemCount: _listAnnonceTeam2.length,
itemBuilder: (BuildContext context, int index){
return new Text(_listAnnonceTeam2[index].toString(), textAlign: TextAlign.center, style:
TextStyle(color: textColor),);
},
),
你知道为什么吗?
解决方案
您需要在后帧回调中进行跳转,以确保该项目将包含在列表中:
SchedulerBinding.instance.addPostFrameCallback((_) {
_controllerAnnonceT1.jumpTo(_controllerAnnonceT1.position.maxScrollExtent);
});
推荐阅读
- c++ - Windows 中的 HeapValidate 有什么作用?
- amazon-web-services - 从 SaaS 应用程序部署独立网站的过程
- c - 添加动态符号名称不适用于 configure.ac 中的 AC_DEFINE_UNQUOTED
- python - 基于 Pandas 中列值的频率计数
- javascript - 从两个单独的数组javascript中删除重复项
- java - 如何在 android studio 中为对象赋值?
- ruby-on-rails - 从 Rails 应用程序到 Rails 引擎 gem 的移动路线
- sql - 此 SQL 触发器代码中是否存在与编译相关的问题
- c# - Elasticsearch NEST 查询嵌套对象
- javascript - Yammer API:以编程方式添加管理员