Updates to debugDisableShadows (#17577)

1. Make CupertinoSwitch use BoxShadow.toPaint() so that it respects
   the `debugDisableShadows` flag.
2. Increase blue radius on debug banner
3. Only stroke "synthetic shadow" borders if elevation is positive.
This commit is contained in:
Todd Volkert 2018-05-15 08:55:42 -07:00 committed by GitHub
parent 8be2682ee4
commit c4cb0ecff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 30 deletions

View File

@ -1 +1 @@
df3f713cc47fc4e919d1c5cf52c0543424c26c09 298b585e6eb2bf51b12cd0ea9261a1b7a83c9a29

View File

@ -6,8 +6,6 @@ import 'package:flutter/painting.dart';
import 'colors.dart'; import 'colors.dart';
final MaskFilter _kShadowMaskFilter = new MaskFilter.blur(BlurStyle.normal, BoxShadow.convertRadiusToSigma(1.0));
/// Paints an iOS-style slider thumb. /// Paints an iOS-style slider thumb.
/// ///
/// Used by [CupertinoSwitch] and [CupertinoSlider]. /// Used by [CupertinoSwitch] and [CupertinoSlider].
@ -16,7 +14,10 @@ class CupertinoThumbPainter {
CupertinoThumbPainter({ CupertinoThumbPainter({
this.color: CupertinoColors.white, this.color: CupertinoColors.white,
this.shadowColor: const Color(0x2C000000), this.shadowColor: const Color(0x2C000000),
}); }) : _shadowPaint = new BoxShadow(
color: shadowColor,
blurRadius: 1.0,
).toPaint();
/// The color of the interior of the thumb. /// The color of the interior of the thumb.
final Color color; final Color color;
@ -24,6 +25,9 @@ class CupertinoThumbPainter {
/// The color of the shadow case by the thumb. /// The color of the shadow case by the thumb.
final Color shadowColor; final Color shadowColor;
/// The paint used to draw the shadow case by the thumb.
final Paint _shadowPaint;
/// Half the default diameter of the thumb. /// Half the default diameter of the thumb.
static const double radius = 14.0; static const double radius = 14.0;
@ -35,17 +39,13 @@ class CupertinoThumbPainter {
/// Consider using [radius] and [extension] when deciding how large a /// Consider using [radius] and [extension] when deciding how large a
/// rectangle to use for the thumb. /// rectangle to use for the thumb.
void paint(Canvas canvas, Rect rect) { void paint(Canvas canvas, Rect rect) {
final RRect rrect = new RRect.fromRectAndRadius(rect, new Radius.circular(rect.shortestSide / 2.0)); final RRect rrect = new RRect.fromRectAndRadius(
rect,
new Radius.circular(rect.shortestSide / 2.0),
);
final Paint paint = new Paint() canvas.drawRRect(rrect, _shadowPaint);
..color = shadowColor canvas.drawRRect(rrect.shift(const Offset(0.0, 3.0)), _shadowPaint);
..maskFilter = _kShadowMaskFilter; canvas.drawRRect(rrect, new Paint()..color = color);
canvas.drawRRect(rrect, paint);
canvas.drawRRect(rrect.shift(const Offset(0.0, 3.0)), paint);
paint
..color = color
..maskFilter = null;
canvas.drawRRect(rrect, paint);
} }
} }

View File

@ -1600,13 +1600,15 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
bool paintShadows = true; bool paintShadows = true;
assert(() { assert(() {
if (debugDisableShadows) { if (debugDisableShadows) {
context.canvas.drawRRect( if (elevation > 0.0) {
offsetRRect, context.canvas.drawRRect(
new Paint() offsetRRect,
..color = shadowColor new Paint()
..style = PaintingStyle.stroke ..color = shadowColor
..strokeWidth = elevation * 2.0, ..style = PaintingStyle.stroke
); ..strokeWidth = elevation * 2.0,
);
}
paintShadows = false; paintShadows = false;
} }
return true; return true;
@ -1721,13 +1723,15 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
bool paintShadows = true; bool paintShadows = true;
assert(() { assert(() {
if (debugDisableShadows) { if (debugDisableShadows) {
context.canvas.drawPath( if (elevation > 0.0) {
offsetPath, context.canvas.drawPath(
new Paint() offsetPath,
..color = shadowColor new Paint()
..style = PaintingStyle.stroke ..color = shadowColor
..strokeWidth = elevation * 2.0, ..style = PaintingStyle.stroke
); ..strokeWidth = elevation * 2.0,
);
}
paintShadows = false; paintShadows = false;
} }
return true; return true;

View File

@ -110,7 +110,7 @@ class BannerPainter extends CustomPainter {
static const BoxShadow _shadow = const BoxShadow( static const BoxShadow _shadow = const BoxShadow(
color: const Color(0x7F000000), color: const Color(0x7F000000),
blurRadius: 4.0, blurRadius: 6.0,
); );
bool _prepared = false; bool _prepared = false;