将项目添加到列表时如何获取maxScrollExtent

时间:2020-07-01 13:33:15

标签: flutter

当我将一个项目添加到列表时,我想滚动到底部,所以我这样做:

SchedulerBinding.instance.addPostFrameCallback((_) {
  print('maxScrollExtent: ${messageListViewCtrl.position.maxScrollExtent}');
  messageListViewCtrl.animateTo(
    messageListViewCtrl.position.maxScrollExtent,
    duration: const Duration(milliseconds: 100),
    curve: Curves.easeOut,
  );
});

但是maxScrollExtent不是最新的,仍然是上次,我只做: Future.delay(Duration(seconds: 2), () { //messageListViewCtrl.position.maxScrollExtent, now it's latest ! })

0 个答案:

没有答案