我的屏幕上有一个listView.我已经附加了一个控制器.我可以调用我的端点,接收响应,解析它并插入行.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,
);
}
Run Code Online (Sandbox Code Playgroud)
问题是,我_toEnd()在最后一项插入列表之前调用函数.所以,我正在寻找一个回调(如果有的话)告诉我build()完成了.然后我打电话给我的_toEnd()功能.
在这种情况下,最佳做法是什么?
flutter ×1