Reputation: 6033
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.
Upvotes: 54
Views: 42772
Reputation: 679
I changed it like this.
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData.light().copyWith(
scrollbarTheme: ScrollbarThemeData().copyWith(
thumbColor: MaterialStateProperty.all(Colors.grey[500]),
)
),
);
}
}
Upvotes: 30
Reputation: 1016
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
)
Upvotes: 100
Reputation: 257
Flutter now provides scrollbarTheme you can use it to set global scroll bar theme and change the thumbColor property as shown below
ScrollbarThemeData(
interactive: true,
isAlwaysShown: true,
radius: const Radius.circular(10.0),
thumbColor: MaterialStateProperty.all(
DarkAppColors.primaryTextColor.withOpacity(0.4),
),
thickness: MaterialStateProperty.all(5.0),
minThumbLength: 100,
)
Upvotes: 14
Reputation: 1792
I personally prefer not to manually set a color to the scrollbar, as it doesn't behave the same way as the default one unless you set the colors for every material state. A solution that worked perfectly for me was to wrap the ListView
in a Theme
widget and set the colorScheme
to one with a Brightness.dark
brightness.
Theme(
data: ThemeData(colorScheme: const ColorScheme.dark()),
child: ListView(...),
)
Upvotes: 0
Reputation:
Scroll bar uses the highlight color.. so just add ur desired scrollbar color in the highlightColor inside Theme in MaterialApp and you are done.
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
//main color
primaryColor: const Color(0xffFFC600),
//main font
fontFamily: 'Roboto-Medium',
//swatch stretching
primarySwatch: goldenThemeColor,
visualDensity: VisualDensity.adaptivePlatformDensity,
splashColor: const Color(0xffFFC600),
//color for scrollbar
highlightColor: Color(0xffffc600)
),
routes: {
'/' : (context) => SplashScreen(),
...
}
initialRoute: '/',
)
Upvotes: 19
Reputation: 575
you could clone the file you linked and change the color inside your project, and then instead of using Scrollbar() use, for example, MyScrollBar(), the edited file you cloned
Upvotes: 0