diff --git a/bin/internal/goldens.version b/bin/internal/goldens.version index a897d02011..880c390523 100644 --- a/bin/internal/goldens.version +++ b/bin/internal/goldens.version @@ -1 +1 @@ -298b585e6eb2bf51b12cd0ea9261a1b7a83c9a29 +95f60c7e328b53dd65de18a608830a872a92e3cd diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index 9637146901..a6c69e5045 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -1004,10 +1004,10 @@ class RenderBackdropFilter extends RenderProxyBox { /// /// See also: /// -/// * [ClipRect], which can be customized with a [CustomClipper]. -/// * [ClipRRect], which can be customized with a [CustomClipper]. -/// * [ClipOval], which can be customized with a [CustomClipper]. -/// * [ClipPath], which can be customized with a [CustomClipper]. +/// * [ClipRect], which can be customized with a [CustomClipper]. +/// * [ClipRRect], which can be customized with a [CustomClipper]. +/// * [ClipOval], which can be customized with a [CustomClipper]. +/// * [ClipPath], which can be customized with a [CustomClipper]. abstract class CustomClipper { /// Creates a custom clipper. /// diff --git a/packages/flutter/test/widgets/clip_test.dart b/packages/flutter/test/widgets/clip_test.dart index 8eed51aafb..10edd5ce3e 100644 --- a/packages/flutter/test/widgets/clip_test.dart +++ b/packages/flutter/test/widgets/clip_test.dart @@ -247,4 +247,275 @@ void main() { ); debugPaintSizeEnabled = false; }); + + testWidgets('ClipRect painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new ClipRect( + child: new Container( + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.ClipRect.1.png'), + ); + }); + + testWidgets('ClipRRect painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new ClipRRect( + borderRadius: const BorderRadius.only( + topLeft: const Radius.elliptical(10.0, 20.0), + topRight: const Radius.elliptical(5.0, 30.0), + bottomLeft: const Radius.elliptical(2.5, 12.0), + bottomRight: const Radius.elliptical(15.0, 6.0), + ), + child: new Container( + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.ClipRRect.1.png'), + ); + }); + + testWidgets('ClipOval painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new ClipOval( + child: new Container( + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.ClipOval.1.png'), + ); + }); + + testWidgets('ClipPath painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new ClipPath( + clipper: new ShapeBorderClipper( + shape: new BeveledRectangleBorder( + borderRadius: new BorderRadius.circular(20.0), + ), + ), + child: new Container( + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.ClipPath.1.png'), + ); + }); + + testWidgets('PhysicalModel painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new PhysicalModel( + borderRadius: new BorderRadius.circular(20.0), + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.PhysicalModel.1.png'), + ); + }); + + testWidgets('PhysicalShape painting', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new RepaintBoundary( + child: new Container( + color: Colors.white, + child: new Padding( + padding: const EdgeInsets.all(100.0), + child: new SizedBox( + height: 100.0, + width: 100.0, + child: new Transform.rotate( + angle: 1.0, // radians + child: new PhysicalShape( + clipper: new ShapeBorderClipper( + shape: new BeveledRectangleBorder( + borderRadius: new BorderRadius.circular(20.0), + ), + ), + color: Colors.red, + child: new Container( + color: Colors.white, + child: new RepaintBoundary( + child: new Center( + child: new Container( + color: Colors.black, + height: 10.0, + width: 10.0, + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ); + await expectLater( + find.byType(RepaintBoundary).first, + matchesGoldenFile('clip.PhysicalShape.1.png'), + ); + }); } diff --git a/packages/flutter_test/lib/src/goldens.dart b/packages/flutter_test/lib/src/goldens.dart index 6061d1fe9a..f0142ead84 100644 --- a/packages/flutter_test/lib/src/goldens.dart +++ b/packages/flutter_test/lib/src/goldens.dart @@ -60,9 +60,9 @@ abstract class GoldenFileComparator { /// When using `flutter test --update-goldens`, the [LocalFileComparator] /// updates the files on disk to match the rendering. /// -/// When using `flutter run`, the default comparator (null) is used. It prints -/// a message to the console but otherwise does nothing. This allows tests to -/// be developed visually on a real device. +/// When using `flutter run`, the default comparator ([TrivialComparator]) +/// is used. It prints a message to the console but otherwise does nothing. This +/// allows tests to be developed visually on a real device. /// /// Callers may choose to override the default comparator by setting this to a /// custom comparator during test set-up (or using directory-level test @@ -75,12 +75,11 @@ abstract class GoldenFileComparator { /// /// * [flutter_test] for more information about how to configure tests at the /// directory-level. -GoldenFileComparator get goldenFileComparator { - return _goldenFileComparator == const _UninitializedComparator() ? null : _goldenFileComparator; -} -GoldenFileComparator _goldenFileComparator = const _UninitializedComparator(); -set goldenFileComparator(GoldenFileComparator comparator) { - _goldenFileComparator = comparator ?? const _UninitializedComparator(); +GoldenFileComparator get goldenFileComparator => _goldenFileComparator; +GoldenFileComparator _goldenFileComparator = const TrivialComparator._(); +set goldenFileComparator(GoldenFileComparator value) { + assert(value != null); + _goldenFileComparator = value; } /// Whether golden files should be automatically updated during tests rather @@ -111,8 +110,11 @@ bool autoUpdateGoldenFiles = false; /// via `flutter run`. In this case, the [compare] method will just print a /// message that it would have otherwise run a real comparison, and it will /// return trivial success. -class _UninitializedComparator implements GoldenFileComparator { - const _UninitializedComparator(); +/// +/// This class can't be constructed. It represents the default value of +/// [goldenFileComparator]. +class TrivialComparator implements GoldenFileComparator { + const TrivialComparator._(); @override Future compare(Uint8List imageBytes, Uri golden) {