Unverified Commit 0d3d8d4b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[framework] respect debugDisableShadows in slider thumbs (#105467)

parent 9f735613
...@@ -2366,7 +2366,19 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2366,7 +2366,19 @@ class RoundSliderThumbShape extends SliderComponentShape {
final double evaluatedElevation = elevationTween.evaluate(activationAnimation); final double evaluatedElevation = elevationTween.evaluate(activationAnimation);
final Path path = Path() final Path path = Path()
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
_debugDrawShadow(canvas, path, evaluatedElevation);
paintShadows = false;
}
return true;
}());
if (paintShadows) {
canvas.drawShadow(path, Colors.black, evaluatedElevation, true); canvas.drawShadow(path, Colors.black, evaluatedElevation, true);
}
canvas.drawCircle( canvas.drawCircle(
center, center,
...@@ -2475,7 +2487,19 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape { ...@@ -2475,7 +2487,19 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
final double evaluatedElevation = isPressed! ? elevationTween.evaluate(activationAnimation) : elevation; final double evaluatedElevation = isPressed! ? elevationTween.evaluate(activationAnimation) : elevation;
final Path shadowPath = Path() final Path shadowPath = Path()
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
_debugDrawShadow(canvas, shadowPath, evaluatedElevation);
paintShadows = false;
}
return true;
}());
if (paintShadows) {
canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true); canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true);
}
canvas.drawCircle( canvas.drawCircle(
center, center,
...@@ -3359,3 +3383,15 @@ class RangeLabels { ...@@ -3359,3 +3383,15 @@ class RangeLabels {
return '${objectRuntimeType(this, 'RangeLabels')}($start, $end)'; 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,
);
}
}
...@@ -1276,8 +1276,10 @@ void main() { ...@@ -1276,8 +1276,10 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor) ..path(color: sliderTheme.valueIndicatorColor)
..paragraph(), ..paragraph()
); );
await gesture.up(); await gesture.up();
// Wait for value indicator animation to finish. // Wait for value indicator animation to finish.
...@@ -1360,7 +1362,7 @@ void main() { ...@@ -1360,7 +1362,7 @@ void main() {
); );
// Represents the Raised Button and Range Slider. // Represents the Raised Button and Range Slider.
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 4)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 6));
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawParagraph, 3)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawParagraph, 3));
await tester.tap(find.text('Next')); await tester.tap(find.text('Next'));
...@@ -1519,6 +1521,8 @@ void main() { ...@@ -1519,6 +1521,8 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor) ..path(color: sliderTheme.valueIndicatorColor)
..paragraph(), ..paragraph(),
); );
...@@ -1594,6 +1598,8 @@ void main() { ...@@ -1594,6 +1598,8 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..path(color: Colors.black) // shadow
..path(color: Colors.black) // shadow
..path(color: sliderTheme.valueIndicatorColor) ..path(color: sliderTheme.valueIndicatorColor)
..paragraph(), ..paragraph(),
); );
......
...@@ -627,6 +627,8 @@ void main() { ...@@ -627,6 +627,8 @@ void main() {
}); });
testWidgets('Slider uses the right theme colors for the right components', (WidgetTester tester) async { testWidgets('Slider uses the right theme colors for the right components', (WidgetTester tester) async {
debugDisableShadows = false;
try {
const Color customColor1 = Color(0xcafefeed); const Color customColor1 = Color(0xcafefeed);
const Color customColor2 = Color(0xdeadbeef); const Color customColor2 = Color(0xdeadbeef);
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
...@@ -838,6 +840,9 @@ void main() { ...@@ -838,6 +840,9 @@ void main() {
..path(color: sliderTheme.valueIndicatorColor), // indicator ..path(color: sliderTheme.valueIndicatorColor), // indicator
); );
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('Slider can tap in vertical scroller', (WidgetTester tester) async { testWidgets('Slider can tap in vertical scroller', (WidgetTester tester) async {
...@@ -1033,6 +1038,8 @@ void main() { ...@@ -1033,6 +1038,8 @@ void main() {
}); });
testWidgets('Slider respects textScaleFactor', (WidgetTester tester) async { testWidgets('Slider respects textScaleFactor', (WidgetTester tester) async {
debugDisableShadows = false;
try {
final Key sliderKey = UniqueKey(); final Key sliderKey = UniqueKey();
double value = 0.0; double value = 0.0;
...@@ -1179,6 +1186,9 @@ void main() { ...@@ -1179,6 +1186,9 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async { testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async {
...@@ -2552,7 +2562,7 @@ void main() { ...@@ -2552,7 +2562,7 @@ void main() {
..paragraph(), ..paragraph(),
); );
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 3)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 4));
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawParagraph, 2)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawParagraph, 2));
await tester.tap(find.text('Next')); await tester.tap(find.text('Next'));
......
...@@ -362,6 +362,8 @@ void main() { ...@@ -362,6 +362,8 @@ void main() {
}); });
testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async { testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async {
debugDisableShadows = false;
try {
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
...@@ -536,9 +538,14 @@ void main() { ...@@ -536,9 +538,14 @@ void main() {
), ),
); );
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async { testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async {
debugDisableShadows = false;
try {
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
...@@ -713,6 +720,9 @@ void main() { ...@@ -713,6 +720,9 @@ void main() {
), ),
); );
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('The slider track height can be overridden', (WidgetTester tester) async { testWidgets('The slider track height can be overridden', (WidgetTester tester) async {
...@@ -967,6 +977,8 @@ void main() { ...@@ -967,6 +977,8 @@ void main() {
}); });
testWidgets('The slider can skip all component painting except the thumb', (WidgetTester tester) async { testWidgets('The slider can skip all component painting except the thumb', (WidgetTester tester) async {
debugDisableShadows = false;
try {
// Pump a slider with just a thumb. // Pump a slider with just a thumb.
await tester.pumpWidget(_buildApp( await tester.pumpWidget(_buildApp(
ThemeData().sliderTheme.copyWith( ThemeData().sliderTheme.copyWith(
...@@ -985,6 +997,9 @@ void main() { ...@@ -985,6 +997,9 @@ void main() {
expect(material, paintsExactlyCountTimes(#drawRect, 0)); expect(material, paintsExactlyCountTimes(#drawRect, 0));
expect(material, paintsExactlyCountTimes(#drawCircle, 1)); expect(material, paintsExactlyCountTimes(#drawCircle, 1));
expect(material, paintsExactlyCountTimes(#drawPath, 0)); expect(material, paintsExactlyCountTimes(#drawPath, 0));
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('The slider can skip all component painting except the overlay', (WidgetTester tester) async { testWidgets('The slider can skip all component painting except the overlay', (WidgetTester tester) async {
...@@ -1113,6 +1128,8 @@ void main() { ...@@ -1113,6 +1128,8 @@ void main() {
testWidgets('Default paddle range slider value indicator shape draws correctly', (WidgetTester tester) async { testWidgets('Default paddle range slider value indicator shape draws correctly', (WidgetTester tester) async {
debugDisableShadows = false;
try {
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
...@@ -1155,10 +1172,60 @@ void main() { ...@@ -1155,10 +1172,60 @@ void main() {
); );
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
});
testWidgets('Default paddle range slider value indicator shape draws correctly with debugDisableShadows', (WidgetTester tester) async {
debugDisableShadows = true;
final ThemeData theme = ThemeData(
platform: TargetPlatform.android,
primarySwatch: Colors.blue,
);
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(
thumbColor: Colors.red.shade500,
showValueIndicator: ShowValueIndicator.always,
rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(),
);
await tester.pumpWidget(_buildRangeApp(sliderTheme));
final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
final Offset center = tester.getCenter(find.byType(RangeSlider));
final TestGesture gesture = await tester.startGesture(center);
// Wait for value indicator animation to finish.
await tester.pumpAndSettle();
expect(
valueIndicatorBox,
paints
// physical model
..rrect()
..rrect(rrect: RRect.fromLTRBAndCorners(
24.0, 298.0, 24.0, 302.0,
topLeft: const Radius.circular(2.0),
bottomLeft: const Radius.circular(2.0),
))
..rect(rect: const Rect.fromLTRB(24.0, 297.0, 24.0, 303.0))
..rrect(rrect: RRect.fromLTRBAndCorners(
24.0, 298.0, 776.0, 302.0,
topRight: const Radius.circular(2.0),
bottomRight: const Radius.circular(2.0),
))
..circle(x: 24.0, y: 300.0)
..path(strokeWidth: 1.0 * 2.0, color: Colors.black)
..circle(x: 24.0, y: 300.0)
..path(strokeWidth: 6.0 * 2.0, color: Colors.black)
..circle(x: 24.0, y: 300.0),
);
await gesture.up();
}); });
testWidgets('PaddleRangeSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async { testWidgets('PaddleRangeSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async {
debugDisableShadows = false;
try {
// Pump a slider with just a value indicator. // Pump a slider with just a value indicator.
await tester.pumpWidget(_buildRangeApp( await tester.pumpWidget(_buildRangeApp(
ThemeData().sliderTheme.copyWith( ThemeData().sliderTheme.copyWith(
...@@ -1169,7 +1236,7 @@ void main() { ...@@ -1169,7 +1236,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
// final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider)); // final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay)); final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
// Tap the center of the track to kick off the animation of the value indicator. // Tap the center of the track to kick off the animation of the value indicator.
...@@ -1185,9 +1252,14 @@ void main() { ...@@ -1185,9 +1252,14 @@ void main() {
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2));
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('Default range indicator shape skips all painting at zero scale', (WidgetTester tester) async { testWidgets('Default range indicator shape skips all painting at zero scale', (WidgetTester tester) async {
debugDisableShadows = false;
try {
// Pump a slider with just a value indicator. // Pump a slider with just a value indicator.
await tester.pumpWidget(_buildRangeApp( await tester.pumpWidget(_buildRangeApp(
ThemeData().sliderTheme.copyWith( ThemeData().sliderTheme.copyWith(
...@@ -1216,6 +1288,9 @@ void main() { ...@@ -1216,6 +1288,9 @@ void main() {
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2)); expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 2));
await gesture.up(); await gesture.up();
} finally {
debugDisableShadows = true;
}
}); });
testWidgets('activeTrackRadius is taken into account when painting the border of the active track', (WidgetTester tester) async { testWidgets('activeTrackRadius is taken into account when painting the border of the active track', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment