问题
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