Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove scroll glow?

Tags:

flutter

dart

By default, flutter adds a glowing effect on ListView/GridView/... to overscrolls on android phones

I would like to remove this effect entirely or on one specific scrollable. I know that I can change ScrollPhysics to change between Bounce/Clamp. But this doesn't actually remove the glow effect.

What can I do ?

enter image description here

like image 734
Rémi Rousselet Avatar asked Jul 01 '18 01:07

Rémi Rousselet


People also ask

How do you remove the glow effect in flutter?

The glow effect comes from GlowingOverscrollIndicator added by ScrollBehavior. To remove this effect, you need to specify a custom ScrollBehavior. For that, simply wrap any given part of your application into a ScrollConfiguration with the desired ScrollBehavior.

What is ClampingScrollPhysics?

ClampingScrollPhysics class Null safety. Scroll physics for environments that prevent the scroll offset from reaching beyond the bounds of the content. This is the behavior typically seen on Android. See also: ScrollConfiguration, which uses this to provide the default scroll behavior on Android.


3 Answers

The glow effect comes from GlowingOverscrollIndicator added by ScrollBehavior

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

The following ScrollBehavior will remove the glow effect entirely :

class MyBehavior extends ScrollBehavior {
  @override
  Widget buildOverscrollIndicator(
      BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}

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

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

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

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

This is also valid if you want to change the effect. Like adding a fade when reaching borders of the scroll view.

like image 167
Rémi Rousselet Avatar answered Nov 01 '22 23:11

Rémi Rousselet


The glow will disappear by changing the ListView's physics property to BouncingScrollPhysics to imitate the List behavior on iOS.

ListView.builder(
    physics: BouncingScrollPhysics(),
}
like image 23
Eddy Liu Avatar answered Nov 01 '22 23:11

Eddy Liu


The above solution did not work for me. I did this from another solution.

Wrap it with this widget to remove the shadow completely:

NotificationListener<OverscrollIndicatorNotification>(
  onNotification: (overscroll) {
    overscroll.disallowGlow();
  },
  child: new ListView.builder(
    //Your stuff here. 
  ),
),
like image 29
Bensal Avatar answered Nov 02 '22 00:11

Bensal