【问题标题】:How to remove overscroll on ios?如何去除ios上的过度滚动?
【发布时间】:2020-02-26 21:55:53
【问题描述】:

默认情况下,flutter在ios上对ListView/GridView/...添加了overscroll效果

我想完全或在一个特定的可滚动项上删除此效果。

我能做什么?

【问题讨论】:

  • 这能回答你的问题吗? How to remove scroll glow?
  • 不,这个答案没有解释如何消除 ios 上的过度滚动效果

标签: flutter dart flutter-layout bounce flutter-listview


【解决方案1】:

我找到了这个答案 (https://stackoverflow.com/a/51119796/5869913) 并添加了有关删除过度滚动效果的信息。

超滚动效果来自BouncingScrollPhysics添加ScrollBehavior

要移除此效果,您需要指定自定义ScrollBehavior 并覆盖getScrollPhysics 方法。为此,只需将应用程序的任何给定部分包装到带有所需 ScrollBehaviorScrollConfiguration 中。

以下 ScrollBehavior 将完全移除过度滚动效果:

class MyBehavior extends ScrollBehavior {
  @override
  ScrollPhysics getScrollPhysics(BuildContext context) => ClampingScrollPhysics();
}

您也可以像这样覆盖方法 buildViewportChrome 来移除发光效果:

@override
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) => child;

要移除整个应用程序的过度滚动,您可以在 MaterialApp 下添加它:

MaterialApp(
  builder: (context, child) {
    return ScrollConfiguration(
      behavior: MyBehavior(),
      child: child,
    );
  },
  home: MyHomePage(),
);

要在特定的 ListView 上删除它,而是只包装所需的 ListView :

ScrollConfiguration(
  behavior: MyBehavior(),
  child: ListView(
    ...
  ),
)

或者只是在 ListView 中设置物理:ClampingScrollPhysics()

【讨论】:

  • 你不能在 ListView 中设置物理:ClampingScrollPhysics() 吗?
  • 能否请您添加完整的示例或 Git 代码?
【解决方案2】:

如果您只想移除 iOS 上的过度滚动行为,则不需要做那些花哨的事情。简单地说,使用:

ListView(
  physics: ClampingScrollPhysics(),
)

【讨论】:

    【解决方案3】:

    在 BouncingScrollPhysics() 中添加 shrinkWrap: true,将移除顶部弹跳。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      • 2017-10-05
      • 2018-12-09
      • 2017-04-07
      • 1970-01-01
      • 2021-06-30
      相关资源
      最近更新 更多