androiddartflutterflutter-layout

How to set Scrollbar colour in flutter?


I have a normal ListView which is wrapped by the Scrollbar class to produce a scrollbar when scrolling down. But I want to change the Scrollbar color to white since I have a dark background.

After exploring the Scrollbar class I can see that it uses the theme highlightColor as shown inside scrollbar.dart.

_themeColor = theme.highlightColor.withOpacity(1.0);

Tried wrapping the Scrollbar in a Theme but still no luck.

Below is my code -

Theme(
  data: ThemeData(
    highlightColor: Colors.white, //Does not work
  ),
  child: Scrollbar(
    child: ListView(
      //Normal ListView code
    ),
  ),
)

Any help is appreciated. Thanks in advance.


Solution

  • You can use RawScrollbar instead and set the thumbColor to whatever color you like.

    child: RawScrollbar(
      thumbColor: Colors.redAccent,
      radius: Radius.circular(20),
      thickness: 5,
      child: // scrollable widget
    )