【发布时间】:2018-12-06 16:32:47
【问题描述】:
我正在使用 onpressed() 向下滚动到列表视图的底部, 但我想在不按按钮的情况下实现这一点,
它必须在每次打开屏幕时自动滚动。 我试图把它放在 initState() 它的不工作,但如果我按下按钮它工作
如何让它自动滚动?
工作代码:
floatingActionButton: new FloatingActionButton(child:
Icon(Icons.arrow_downward),onPressed:_hola,)
_hola(){
print("inti state started successfully");
controller1.animateTo(
controller1.position.maxScrollExtent,
duration: const Duration(milliseconds: 10),
curve: Curves.easeOut,);
}
非工作代码: //这段代码打印成功,但没有真正调用函数
class HomeState extends State<MyNewMessages> {
@override
void initState()
{
super.initState();
print("hola is scrolling");
_hola;
}
);
}
【问题讨论】:
-
检查您使用的列表是否有
reverse构造函数参数并传递true,然后它会自动滚动到底部。您还需要以相反的顺序查询数据。 -
@GünterZöchbauer 是的,我只使用反向,问题是它没有滚动到完整列表的底部,它隐藏了一些数据,我的列表有 14 个条目,但它只显示 8 个条目,即使我使用 reverse=false 也会发生这种情况
-
听起来很奇怪。您使用的是什么列表?
-
@GünterZöchbauer 这是facebook.com/rajesh.JumpRoper/videos/2129228357301990的视频
-
@GünterZöchbauer Listview.Builder,只需从 firebase 获取一个集合,然后将它们显示为列表视图
标签: listview flutter flutter-layout flutter-sliver flutter-animation