Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit abfaec6

Browse files
authored
Use ScrollbarTheme instead Theme for Scrollbar (#113237)
1 parent 3d94b8f commit abfaec6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/flutter/lib/src/material/scrollbar.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
399399
void didChangeDependencies() {
400400
final ThemeData theme = Theme.of(context);
401401
_colorScheme = theme.colorScheme;
402-
_scrollbarTheme = theme.scrollbarTheme;
402+
_scrollbarTheme = ScrollbarTheme.of(context);
403403
switch (theme.platform) {
404404
case TargetPlatform.android:
405405
_useAndroidScrollbar = true;

packages/flutter/test/material/scrollbar_theme_test.dart

+44
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,50 @@ void main() {
206206
}),
207207
);
208208

209+
testWidgets(
210+
'Scrollbar uses values from ScrollbarTheme if exists instead of values from Theme',
211+
(WidgetTester tester) async {
212+
final ScrollbarThemeData scrollbarTheme = _scrollbarTheme();
213+
final ScrollController scrollController = ScrollController();
214+
await tester.pumpWidget(
215+
MaterialApp(
216+
theme: ThemeData(
217+
scrollbarTheme: scrollbarTheme,
218+
),
219+
home: ScrollConfiguration(
220+
behavior: const NoScrollbarBehavior(),
221+
child: ScrollbarTheme(
222+
data: _scrollbarTheme().copyWith(
223+
thumbColor: MaterialStateProperty.all(const Color(0xFF000000)),
224+
),
225+
child: Scrollbar(
226+
thumbVisibility: true,
227+
controller: scrollController,
228+
child: SingleChildScrollView(
229+
controller: scrollController,
230+
child: const SizedBox(width: 4000.0, height: 4000.0),
231+
),
232+
),
233+
),
234+
),
235+
),
236+
);
237+
await tester.pumpAndSettle();
238+
// Idle scrollbar behavior
239+
expect(
240+
find.byType(Scrollbar),
241+
paints
242+
..rrect(
243+
rrect: RRect.fromRectAndRadius(
244+
const Rect.fromLTRB(785.0, 10.0, 795.0, 97.0),
245+
const Radius.circular(6.0),
246+
),
247+
color: const Color(0xFF000000),
248+
),
249+
);
250+
},
251+
);
252+
209253
testWidgets('ScrollbarTheme can disable gestures', (WidgetTester tester) async {
210254
final ScrollController scrollController = ScrollController();
211255
await tester.pumpWidget(MaterialApp(

0 commit comments

Comments
 (0)