How to remove overscroll on ios?

给你一囗甜甜゛ 提交于 2020-01-11 07:32:06

问题


By default, flutter adds a overscroll effect on ListView/GridView/... on ios

I would like to remove this effect entirely or on one specific scrollable.

What can I do ?


回答1:


I found this answer (https://stackoverflow.com/a/51119796/5869913) and just added information about deleting overscroll effect.

The overscroll effect comes from BouncingScrollPhysics added by ScrollBehavior

To remove this effect, you need to specify a custom ScrollBehavior and override getScrollPhysics method. For that, simply wrap any given part of your application into a ScrollConfiguration with the desired ScrollBehavior.

The following ScrollBehavior will remove the overscroll effect entirely :

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

You can also remove glow effect with override of method buildViewportChrome like this:

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

To remove the overscroll on the whole application, you can add it right under MaterialApp :

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

To remove it on a specific ListView, instead wrap only the desired ListView :

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

or just set physics: ClampingScrollPhysics() in the ListView



来源:https://stackoverflow.com/questions/58645048/how-to-remove-overscroll-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!