diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index 5914516583..e2b14daed4 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -301,6 +301,29 @@ class _MaterialState extends State with TickerProviderStateMixin { ) ); + // PhysicalModel has a temporary workaround for a perfomance issue that + // speeds up rectangular non transparent material (the workaround is to + // skip the call to ui.Canvas.saveLayer if the border radius is 0). + // Until the saveLayer perfomance issue is resolved, we're keeping this + // special case here for canvas material type that is using the default + // shape (rectangle). We could go down this fast path for explicitly + // specified rectangles (e.g shape RoundeRectangleBorder with radius 0, but + // we choose not to as we want the change from the fast-path to the + // slow-path to be noticeable in the construction site of Material. + if (widget.type == MaterialType.canvas && widget.shape == null && widget.borderRadius == null) { + return new AnimatedPhysicalModel( + curve: Curves.fastOutSlowIn, + duration: kThemeChangeDuration, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.zero, + elevation: widget.elevation, + color: backgroundColor, + shadowColor: widget.shadowColor, + animateColor: false, + child: contents, + ); + } + final ShapeBorder shape = _getShape(); if (widget.type == MaterialType.transparency) @@ -347,7 +370,7 @@ class _MaterialState extends State with TickerProviderStateMixin { case MaterialType.card: case MaterialType.button: return new RoundedRectangleBorder( - borderRadius: kMaterialEdges[widget.type], + borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type], ); case MaterialType.circle: diff --git a/packages/flutter/test/material/ink_well_test.dart b/packages/flutter/test/material/ink_well_test.dart index b61fc52a49..5b0872bb9f 100644 --- a/packages/flutter/test/material/ink_well_test.dart +++ b/packages/flutter/test/material/ink_well_test.dart @@ -140,17 +140,17 @@ void main() { ), ), ); - expect(tester.renderObject(find.byType(PhysicalShape)).child, paintsNothing); + expect(tester.renderObject(find.byType(PhysicalModel)).child, paintsNothing); await tester.tap(find.byType(InkWell)); await tester.pump(); await tester.pump(const Duration(milliseconds: 10)); - expect(tester.renderObject(find.byType(PhysicalShape)).child, paints..circle()); + expect(tester.renderObject(find.byType(PhysicalModel)).child, paints..circle()); await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0)); await tester.pump(const Duration(milliseconds: 10)); await tester.drag(find.byType(ListView), const Offset(0.0, 1000.0)); await tester.pump(const Duration(milliseconds: 10)); expect( - tester.renderObject(find.byType(PhysicalShape)).child, + tester.renderObject(find.byType(PhysicalModel)).child, keepAlive ? (paints..circle()) : paintsNothing, ); } diff --git a/packages/flutter/test/material/material_test.dart b/packages/flutter/test/material/material_test.dart index d8ed0fedc7..9be13d582d 100644 --- a/packages/flutter/test/material/material_test.dart +++ b/packages/flutter/test/material/material_test.dart @@ -24,6 +24,7 @@ Widget buildMaterial( child: new Material( shadowColor: shadowColor, elevation: elevation, + shape: const CircleBorder(), ), ), );