From abfaec68114b0616485df3ec2eb2f5c2d76b4ceb Mon Sep 17 00:00:00 2001 From: Oleg <17007214+Oleh-Sv@users.noreply.github.com> Date: Wed, 19 Oct 2022 08:13:17 +0100 Subject: [PATCH] Use ScrollbarTheme instead Theme for Scrollbar (#113237) --- .../flutter/lib/src/material/scrollbar.dart | 2 +- .../test/material/scrollbar_theme_test.dart | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/scrollbar.dart b/packages/flutter/lib/src/material/scrollbar.dart index ff5919ec80b..e282ccc02e8 100644 --- a/packages/flutter/lib/src/material/scrollbar.dart +++ b/packages/flutter/lib/src/material/scrollbar.dart @@ -399,7 +399,7 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { void didChangeDependencies() { final ThemeData theme = Theme.of(context); _colorScheme = theme.colorScheme; - _scrollbarTheme = theme.scrollbarTheme; + _scrollbarTheme = ScrollbarTheme.of(context); switch (theme.platform) { case TargetPlatform.android: _useAndroidScrollbar = true; diff --git a/packages/flutter/test/material/scrollbar_theme_test.dart b/packages/flutter/test/material/scrollbar_theme_test.dart index c666e76fa85..00a2b0aae98 100644 --- a/packages/flutter/test/material/scrollbar_theme_test.dart +++ b/packages/flutter/test/material/scrollbar_theme_test.dart @@ -206,6 +206,50 @@ void main() { }), ); + testWidgets( + 'Scrollbar uses values from ScrollbarTheme if exists instead of values from Theme', + (WidgetTester tester) async { + final ScrollbarThemeData scrollbarTheme = _scrollbarTheme(); + final ScrollController scrollController = ScrollController(); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData( + scrollbarTheme: scrollbarTheme, + ), + home: ScrollConfiguration( + behavior: const NoScrollbarBehavior(), + child: ScrollbarTheme( + data: _scrollbarTheme().copyWith( + thumbColor: MaterialStateProperty.all(const Color(0xFF000000)), + ), + child: Scrollbar( + thumbVisibility: true, + controller: scrollController, + child: SingleChildScrollView( + controller: scrollController, + child: const SizedBox(width: 4000.0, height: 4000.0), + ), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + // Idle scrollbar behavior + expect( + find.byType(Scrollbar), + paints + ..rrect( + rrect: RRect.fromRectAndRadius( + const Rect.fromLTRB(785.0, 10.0, 795.0, 97.0), + const Radius.circular(6.0), + ), + color: const Color(0xFF000000), + ), + ); + }, + ); + testWidgets('ScrollbarTheme can disable gestures', (WidgetTester tester) async { final ScrollController scrollController = ScrollController(); await tester.pumpWidget(MaterialApp(