【问题标题】:How can I disable the animation when you scroll all the way to the top in ListView.builder当您一直滚动到 ListView.builder 的顶部时,如何禁用动画
【发布时间】:2019-04-08 17:50:25
【问题描述】:

我正在尝试在我的颤振应用程序上列出一个列表。但是,每次我一直滚动到顶部时,都会出现这样的动画:

https://i.stack.imgur.com/Z7mHh.jpg, https://i.stack.imgur.com/EAIyj.jpg

有没有办法隐藏这个动画?

【问题讨论】:

    标签: dart flutter flutter-animation


    【解决方案1】:
    NotificationListener<OverscrollIndicatorNotification>(
        onNotification: (OverscrollIndicatorNotification overscroll) {
          overscroll.disallowGlow();
        },
        child: ListView.builder(...));
    

    正如official docs所说

    GlowingOverscrollIndicator 在显示过度滚动指示之前生成 OverscrollIndicatorNotification。要防止指示器显示指示,请在通知上调用 OverscrollIndicatorNotification.disallowGlow。

    【讨论】:

    • 来自official docs:返回true取消通知冒泡。返回 false(或 null)以允许通知继续分派给更远的祖先。
    • 我正在使用 SingChildScrollView 和 Glow Effect Show,那么如何移除 Glow Effect?能否请您添加整个示例或 Git 代码?
    • 您是否尝试使用SingChildScrollView 而不是ListView.builder()
    • 当孩子有BouncingScrollPhysics()行为时,它可以以某种方式使用吗?
    • 没试过。但如果它不能 - 你可以设置另一个滚动物理孩子,我猜
    【解决方案2】:

    这将帮助您将其添加到您的 Listview.builder

    physics: ClampingScrollPhysics(),
    

    【讨论】:

    • ScrollablePositionedList.builder 的任何解决方案?请分享。谢谢。
    【解决方案3】:

    你可以用两种方法解决这个问题。

    1. 如果你负担得起反弹效果,那么只需使用ListView.builder 的属性physics 并像这样设置值BouncingScrollPhysics()

      physics: BouncingScrollPhysics()
      
    2. 您也可以使用ScrollConfiguration 和自定义ScrollBehavior 来解决它。

    See for this post for details.

    【讨论】:

    • physics: BouncingScrollPhysics() 解决方案不适用于ScrollablePositionedList.builder。任何解决方案。谢谢。
    【解决方案4】:

    MD Khali,这里是使用 SingleChildScrollView 的代码

    @override
    Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: NotificationListener<OverscrollIndicatorNotification>(
          onNotification: (OverscrollIndicatorNotification overScroll) {
            overScroll.disallowGlow();
            return false;
          },
          child: SingleChildScrollView( ..... )
        )
      )
     )
    

    【讨论】:

    • 这是最适合我的解决方案,谢谢
    • 我们如何使用它与ScrollablePositionedList.builder 请建议。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2017-06-07
    • 2020-03-16
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多