From 64a23504bb8c928d3c9cfccc42ed9eafb1a0dab5 Mon Sep 17 00:00:00 2001 From: Anhad Singh <62820092+Andy-Python-Programmer@users.noreply.github.com> Date: Thu, 1 Oct 2020 07:55:58 +1000 Subject: [PATCH] Added transformAlignment for container (#66201) --- .../flutter/lib/src/widgets/container.dart | 12 ++++- .../flutter/test/widgets/container_test.dart | 47 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/container.dart b/packages/flutter/lib/src/widgets/container.dart index 3e3f20a1e6..e1ee8b45cb 100644 --- a/packages/flutter/lib/src/widgets/container.dart +++ b/packages/flutter/lib/src/widgets/container.dart @@ -268,6 +268,7 @@ class Container extends StatelessWidget { BoxConstraints? constraints, this.margin, this.transform, + this.transformAlignment, this.child, this.clipBehavior = Clip.none, }) : assert(margin == null || margin.isNonNegative), @@ -356,6 +357,15 @@ class Container extends StatelessWidget { /// The transformation matrix to apply before painting the container. final Matrix4? transform; + /// The alignment of the origin, relative to the size of the container, if [transform] is specified. + /// + /// When [transform] is null, the value of this property is ignored. + /// + /// See also: + /// + /// * [Transform.alignment], which is set by this property. + final Alignment? transformAlignment; + /// The clip behavior when [Container.decoration] is not null. /// /// Defaults to [Clip.none]. Must be [Clip.none] if [decoration] is null. @@ -427,7 +437,7 @@ class Container extends StatelessWidget { current = Padding(padding: margin!, child: current); if (transform != null) - current = Transform(transform: transform!, child: current); + current = Transform(transform: transform!, child: current, alignment: transformAlignment); return current!; } diff --git a/packages/flutter/test/widgets/container_test.dart b/packages/flutter/test/widgets/container_test.dart index 66df7b19e5..5dcb39a8c5 100644 --- a/packages/flutter/test/widgets/container_test.dart +++ b/packages/flutter/test/widgets/container_test.dart @@ -470,6 +470,53 @@ void main() { ); }); + testWidgets('Container transformAlignment', (WidgetTester tester) async { + final Key key = UniqueKey(); + + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: [ + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + color: const Color(0xFF0000FF), + ), + ), + Positioned( + top: 100.0, + left: 100.0, + child: Container( + width: 100.0, + height: 100.0, + key: key, + transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0), + transformAlignment: const Alignment(1.0, 0.0), + child: Container( + color: const Color(0xFF00FFFF), + ), + ), + ), + ], + ), + ), + ); + + final Finder finder = find.byKey(key); + + expect(tester.getSize(finder), equals(const Size(100, 100))); + + expect(tester.getTopLeft(finder), equals(const Offset(100, 100))); + expect(tester.getTopRight(finder), equals(const Offset(200, 100))); + + expect(tester.getBottomLeft(finder), equals(const Offset(100, 200))); + expect(tester.getBottomRight(finder), equals(const Offset(200, 200))); + }); + testWidgets('giving clipBehaviour Clip.None, will not add a ClipPath to the tree', (WidgetTester tester) async { await tester.pumpWidget(Container( clipBehavior: Clip.none,