From 158939a89d2aceeaeb103176f66c8dbf7e943f5f Mon Sep 17 00:00:00 2001 From: nt4f04uNd Date: Thu, 14 Oct 2021 03:58:04 +0300 Subject: [PATCH] Scrollbar shouldRepaint to respect the shape (#91506) --- .../flutter/lib/src/widgets/scrollbar.dart | 7 +-- .../flutter/test/widgets/scrollbar_test.dart | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/widgets/scrollbar.dart b/packages/flutter/lib/src/widgets/scrollbar.dart index b363847589b..2297caafbdf 100644 --- a/packages/flutter/lib/src/widgets/scrollbar.dart +++ b/packages/flutter/lib/src/widgets/scrollbar.dart @@ -697,8 +697,9 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { || mainAxisMargin != oldDelegate.mainAxisMargin || crossAxisMargin != oldDelegate.crossAxisMargin || radius != oldDelegate.radius - || minLength != oldDelegate.minLength + || shape != oldDelegate.shape || padding != oldDelegate.padding + || minLength != oldDelegate.minLength || minOverscrollLength != oldDelegate.minOverscrollLength || scrollbarOrientation != oldDelegate.scrollbarOrientation; } @@ -1311,9 +1312,9 @@ class RawScrollbarState extends State with TickerProv /// /// Subclasses can override to configure the [scrollbarPainter]. @protected - void updateScrollbarPainter() { + void updateScrollbarPainter() { scrollbarPainter - ..color = widget.thumbColor ?? const Color(0x66BCBCBC) + ..color = widget.thumbColor ?? const Color(0x66BCBCBC) ..textDirection = Directionality.of(context) ..thickness = widget.thickness ?? _kScrollbarThickness ..radius = widget.radius diff --git a/packages/flutter/test/widgets/scrollbar_test.dart b/packages/flutter/test/widgets/scrollbar_test.dart index d84467343a1..c7f3433b420 100644 --- a/packages/flutter/test/widgets/scrollbar_test.dart +++ b/packages/flutter/test/widgets/scrollbar_test.dart @@ -2037,4 +2037,56 @@ void main() { expect(depths[0], 1); expect(depths[1], 0); }); + + test('ScrollbarPainter.shouldRepaint returns true when any of the properties changes', () { + ScrollbarPainter createPainter({ + Color color = const Color(0xFF000000), + Animation fadeoutOpacityAnimation = kAlwaysCompleteAnimation, + Color trackColor = const Color(0x00000000), + Color trackBorderColor = const Color(0x00000000), + TextDirection textDirection = TextDirection.ltr, + double thickness = _kThickness, + EdgeInsets padding = EdgeInsets.zero, + double mainAxisMargin = 0.0, + double crossAxisMargin = 0.0, + Radius? radius, + OutlinedBorder? shape, + double minLength = _kMinThumbExtent, + double? minOverscrollLength, + ScrollbarOrientation scrollbarOrientation = ScrollbarOrientation.top, + }) { + return ScrollbarPainter( + color: color, + fadeoutOpacityAnimation: fadeoutOpacityAnimation, + trackColor: trackColor, + trackBorderColor: trackBorderColor, + textDirection: textDirection, + thickness: thickness, + padding: padding, + mainAxisMargin: mainAxisMargin, + crossAxisMargin: crossAxisMargin, + radius: radius, + shape: shape, + minLength: minLength, + minOverscrollLength: minOverscrollLength, + scrollbarOrientation: scrollbarOrientation, + ); + } + final ScrollbarPainter painter = createPainter(); + expect(painter.shouldRepaint(createPainter()), false); + expect(painter.shouldRepaint(createPainter(color: const Color(0xFFFFFFFF))), true); + expect(painter.shouldRepaint(createPainter(fadeoutOpacityAnimation: kAlwaysDismissedAnimation)), true); + expect(painter.shouldRepaint(createPainter(trackColor: const Color(0xFFFFFFFF))), true); + expect(painter.shouldRepaint(createPainter(trackBorderColor: const Color(0xFFFFFFFF))), true); + expect(painter.shouldRepaint(createPainter(textDirection: TextDirection.rtl)), true); + expect(painter.shouldRepaint(createPainter(thickness: _kThickness + 1.0)), true); + expect(painter.shouldRepaint(createPainter(padding: const EdgeInsets.all(1.0))), true); + expect(painter.shouldRepaint(createPainter(mainAxisMargin: 1.0)), true); + expect(painter.shouldRepaint(createPainter(crossAxisMargin: 1.0)), true); + expect(painter.shouldRepaint(createPainter(radius: const Radius.circular(1.0))), true); + expect(painter.shouldRepaint(createPainter(shape: const CircleBorder(side: BorderSide(width: 2.0)))), true); + expect(painter.shouldRepaint(createPainter(minLength: _kMinThumbExtent + 1.0)), true); + expect(painter.shouldRepaint(createPainter(minOverscrollLength: 1.0)), true); + expect(painter.shouldRepaint(createPainter(scrollbarOrientation: ScrollbarOrientation.bottom)), true); + }); }