How to remove overscroll on ios?

后端 未结 2 1778
名媛妹妹
名媛妹妹 2021-01-03 03:39

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

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

相关标签:
2条回答
  • 2021-01-03 04:20

    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

    0 讨论(0)
  • You don't need to do those fancy stuff if you only want to remove overscroll behavior on iOS. Simply, use:

    ListView(
      physics: ClampingScrollPhysics(),
    )
    
    0 讨论(0)
提交回复
热议问题