我的屏幕上有一个列表视图.我已经给它装上了控制器.我能够调用我的端点、接收响应、解析它并将其插入行.ListView应该自动滚动.是的,但不是以完美的方式.我总是落在后面.这是我的代码:
@override
Widget build(BuildContext context) {
// Scroll to the most recent item
if (equationList.length > 0) {
_toEnd();
}
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: EquList(equationList, _scrollController),
floatingActionButton: new FloatingActionButton(
onPressed: onFabClick,
tooltip: 'Fetch Post',
child: new Icon(isLoading ? Icons.pause : Icons.play_arrow),
),
);
}
void _toEnd() {
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 250),
curve: Curves.ease,
);
}
问题是,在最后一项插入列表之前,我调用了_toEnd()
函数.因此,我正在寻找一个回调(如果有),它告诉我build()
已经完成.然后我调用我的_toEnd()
函数.
这种情况下的最佳实践是什么?