Skip to content

Commit

Permalink
[framework] respect debugDisableShadows in slider thumbs (#105467)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Jun 6, 2022
1 parent 9f73561 commit 0d3d8d4
Show file tree
Hide file tree
Showing 4 changed files with 867 additions and 740 deletions.
40 changes: 38 additions & 2 deletions packages/flutter/lib/src/material/slider_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,19 @@ class RoundSliderThumbShape extends SliderComponentShape {
final double evaluatedElevation = elevationTween.evaluate(activationAnimation);
final Path path = Path()
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
canvas.drawShadow(path, Colors.black, evaluatedElevation, true);

bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
_debugDrawShadow(canvas, path, evaluatedElevation);
paintShadows = false;
}
return true;
}());

if (paintShadows) {
canvas.drawShadow(path, Colors.black, evaluatedElevation, true);
}

canvas.drawCircle(
center,
Expand Down Expand Up @@ -2475,7 +2487,19 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
final double evaluatedElevation = isPressed! ? elevationTween.evaluate(activationAnimation) : elevation;
final Path shadowPath = Path()
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true);

bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
_debugDrawShadow(canvas, shadowPath, evaluatedElevation);
paintShadows = false;
}
return true;
}());

if (paintShadows) {
canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true);
}

canvas.drawCircle(
center,
Expand Down Expand Up @@ -3359,3 +3383,15 @@ class RangeLabels {
return '${objectRuntimeType(this, 'RangeLabels')}($start, $end)';
}
}

void _debugDrawShadow(Canvas canvas, Path path, double elevation) {
if (elevation > 0.0) {
canvas.drawPath(
path,
Paint()
..color = Colors.black
..style = PaintingStyle.stroke
..strokeWidth = elevation * 2.0,
);
}
}
20 changes: 13 additions & 7 deletions packages/flutter/test/material/range_slider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,10 @@ void main() {
expect(
valueIndicatorBox,
paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor)
..paragraph(),
..paragraph()
);
await gesture.up();
// Wait for value indicator animation to finish.
Expand Down Expand Up @@ -1360,7 +1362,7 @@ void main() {
);

// Represents the Raised Button and Range Slider.
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 4));
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 6));
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawParagraph, 3));

await tester.tap(find.text('Next'));
Expand All @@ -1370,11 +1372,11 @@ void main() {
expect(
valueIndicatorBox,
isNot(
paints
..path(color: fillColor)
..paragraph()
..path(color: fillColor)
..paragraph(),
paints
..path(color: fillColor)
..paragraph()
..path(color: fillColor)
..paragraph(),
),
);

Expand Down Expand Up @@ -1519,6 +1521,8 @@ void main() {
expect(
valueIndicatorBox,
paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor)
..paragraph(),
);
Expand Down Expand Up @@ -1594,6 +1598,8 @@ void main() {
expect(
valueIndicatorBox,
paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor)
..paragraph(),
);
Expand Down
Loading

0 comments on commit 0d3d8d4

Please sign in to comment.