English 中文(简体)
在传唤书记员时的简历
原标题:Overscroll on ListView when calling scrollController.animateTo
  • 时间:2024-04-30 18:32:05
  •  标签:
  • flutter
  • dart
The bounty expires in 6 days. Answers to this question are eligible for a +100 reputation bounty. Adam B wants to draw more attention to this question.

我有一份名单。 类似:

ListView.builder(
  key: _listViewKey,
  controller: widget.scrollController,
  shrinkWrap: true,
  scrollDirection: Axis.vertical,
  physics: const AlwaysScrollableScrollPhysics(),
  itemCount: state.items,
  itemBuilder: (context, index) {
  ...

此外,我还拥有使用滚动机打电话囚犯的最终方法。 将用户带至名单的底线,而不管其位置如何。 这里指的是:

void scrollToEnd() async {
   await Future.delayed(const Duration(milliseconds: 300));
   Future.doWhile(() {
     if (widget.scrollController.positions.last.extentAfter == 0) {
       return Future.value(false);
     }
     return widget.scrollController.animateTo(widget.scrollController.positions.last.maxScrollExtent, duration: Duration(milliseconds: 500), curve: Curves.linear).then((value) => true);
   });
}

我发现,我叫Aimate 仅仅一次,雕刻就足够了,有时是滚动机走到底,因此制定了doWhile方法。

However now when scrolling up the list a few items and evoking scrollToEnd() there seems to be a pretty severe overscroll and total whitespace is shown until eventually the last list items sinks back down into view. I have 2 questions:

  1. Why is widget.scrollController.positions.last.maxScrollExtent ever returning a higher value than the list actually has?
  2. How can I stop this overscroll from happening? My only goal is that scrollToEnd() gets the list to the end every time and that is doesnt look wonky when it does it.

Edit:所有清单项目的高度各异,因此,我需要一种解决办法,即围绕硬编码固定高度开展工作。

问题回答

如果我正确理解你试图做些什么,也就是要达到名单的结束,那么,我就只是修改了您的<编码>_scrollToEnd的功能,并确保只有在种植花园之后才能使用。

Code

void _scrollToEnd() {
  widget.scrollController.animateTo(
    widget.scrollController.position.maxScrollExtent,
    duration: Duration(milliseconds: 500),
    curve: Curves.linear,
  );
}




相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签