17

Is there any way to remove scrollbar from a SingleChildScrollView and Listview.builder? After the latest update, it appears automatically while scrolling (Platform Windows).

I've tried this solution:

 NotificationListener<ScrollNotification>(
     onNotification: (_) => true,
     child: ...,
    );

And also tried to wrap my widget tree in a Scrollbar widget with isAlwaysShown and controller, but both variants didn't work.

Still here

old_timer
  • 69,149
  • 8
  • 89
  • 168
Kirill
  • 1,129
  • 1
  • 7
  • 16

3 Answers3

63

To hide a scrollbar on desktop/web wrap your widget tree in a ScrollConfiguration widget with behavior of ScrollConfiguration.of(context).copyWith(scrollbars: false),

 ScrollConfiguration(
      behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
      child: ...,),

or you can add scrollBehavior to MaterialApp widget

class NoThumbScrollBehavior extends ScrollBehavior {
  @override
  Set<PointerDeviceKind> get dragDevices => {
        PointerDeviceKind.touch,
        PointerDeviceKind.mouse,
        PointerDeviceKind.stylus,
        PointerDeviceKind.trackpad,
      };
}

return MaterialApp(
      debugShowCheckedModeBanner: false,
      scrollBehavior: NoThumbScrollBehavior().copyWith(scrollbars: false),
      home: MainWindow(),
    );
Kirill
  • 1,129
  • 1
  • 7
  • 16
  • Add also PointerDeviceKind.trackpad into the dragDevices getter for the ones who use laptops without a mouse '^^ – Hyung Tae Carapeto Figur Aug 17 '23 at 12:53
  • Thank you, i've updated the example, however, i tested the overall behavior of my app without this trackpad support and it's working great on the laptop, so i don't really see the reason of adding such behavior support to the app – Kirill Aug 25 '23 at 07:26
  • Thanks :) I commented that because it wasn't working for me. Only adding that line that worked. I'm using an Intel MacBook Air. – Hyung Tae Carapeto Figur Aug 27 '23 at 22:23
14

Wrap your scrollable widget in ScrollConfiguration

ScrollConfiguration(
 behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
 child: ListView(...)
)
Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
0

The easiest and quickest way to achieve this is to set thickness: 0 on the Scrollbar widget. It'll look something like this:

 Scrollbar(
          thickness: 0,
          child: ...
 )