From d3022132700bf6e258a3b8dd38f6a0e7cbecaf4d Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 4 Apr 2017 16:42:48 -0700 Subject: [PATCH] Gate the PhysicalModel shadows behind a flag (#9198) Fixes https://github.com/flutter/flutter/issues/9186 --- .../flutter/lib/src/material/material.dart | 53 ++++++++++++------- .../flutter/test/material/ink_paint_test.dart | 2 + 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index fdd7ab8980..b7837fa81f 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'constants.dart'; +import 'shadows.dart'; import 'theme.dart'; /// Signature for the callback used by ink effects to obtain the rectangle for the effect. @@ -187,6 +188,9 @@ class Material extends StatefulWidget { /// The default radius of an ink splash in logical pixels. static const double defaultSplashRadius = 35.0; + + // Temporary flag used to enable the PhysicalModel shadow implementation. + static bool debugEnablePhysicalModel = false; } class _MaterialState extends State with TickerProviderStateMixin { @@ -232,30 +236,41 @@ class _MaterialState extends State with TickerProviderStateMixin { ) ); - if (config.type == MaterialType.circle) { - contents = new PhysicalModel( - shape: BoxShape.circle, - elevation: config.elevation, - color: backgroundColor, - child: contents, - ); - } else if (config.type == MaterialType.transparency) { - if (radius == null) { - contents = new ClipRect(child: contents); + if (Material.debugEnablePhysicalModel) { + if (config.type == MaterialType.circle) { + contents = new PhysicalModel( + shape: BoxShape.circle, + elevation: config.elevation, + color: backgroundColor, + child: contents, + ); + } else if (config.type == MaterialType.transparency) { + if (radius == null) { + contents = new ClipRect(child: contents); + } else { + contents = new ClipRRect( + borderRadius: radius, + child: contents + ); + } } else { + contents = new PhysicalModel( + shape: BoxShape.rectangle, + borderRadius: radius ?? BorderRadius.zero, + elevation: config.elevation, + color: backgroundColor, + child: contents, + ); + } + } else { + if (config.type == MaterialType.circle) { + contents = new ClipOval(child: contents); + } else if (kMaterialEdges[config.type] != null) { contents = new ClipRRect( borderRadius: radius, child: contents ); } - } else { - contents = new PhysicalModel( - shape: BoxShape.rectangle, - borderRadius: radius ?? BorderRadius.zero, - elevation: config.elevation, - color: backgroundColor, - child: contents, - ); } if (config.type != MaterialType.transparency) { @@ -264,6 +279,8 @@ class _MaterialState extends State with TickerProviderStateMixin { duration: kThemeChangeDuration, decoration: new BoxDecoration( borderRadius: radius, + boxShadow: config.elevation == 0 || Material.debugEnablePhysicalModel ? + null : kElevationToShadow[config.elevation], shape: config.type == MaterialType.circle ? BoxShape.circle : BoxShape.rectangle ), child: new Container( diff --git a/packages/flutter/test/material/ink_paint_test.dart b/packages/flutter/test/material/ink_paint_test.dart index 7d4d5e455d..41b00146cc 100644 --- a/packages/flutter/test/material/ink_paint_test.dart +++ b/packages/flutter/test/material/ink_paint_test.dart @@ -9,6 +9,8 @@ import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; void main() { + Material.debugEnablePhysicalModel = true; + testWidgets('Does the ink widget render a border radius', (WidgetTester tester) async { final Color highlightColor = new Color(0xAAFF0000); final Color splashColor = new Color(0xAA0000FF);