From 83c7108c99a8303b09bf53bf4f68c8ec379f084d Mon Sep 17 00:00:00 2001 From: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:35:59 -0400 Subject: [PATCH] docs: Clarify Transform.rotate origin interaction with alignment (#163934) This commit improves the documentation for Transform.rotate's origin property to clarify its interaction with the alignment property. Before: The documentation did not clearly explain how the origin offset interacts with the alignment property, potentially leading to confusion about the actual rotation point. After: The documentation now emphasizes that the origin offset is applied after the alignment transformation, and provides examples to avoid common misinterpretations. This change ensures developers can correctly position the rotation point. --------- Co-authored-by: Greg Price --- packages/flutter/lib/src/widgets/basic.dart | 39 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index ffb62fd6d77..c676b608ce0 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -1722,15 +1722,50 @@ class Transform extends SingleChildRenderObjectWidget { /// The matrix to transform the child by during painting. final Matrix4 transform; - /// The origin of the coordinate system (relative to the upper left corner of - /// this render object) in which to apply the matrix. + /// The origin of the coordinate system in which to apply the matrix, + /// described relative to the point given by [alignment]. /// /// Setting an origin is equivalent to conjugating the transform matrix by a /// translation. This property is provided just for convenience. + /// + /// This offset is applied in addition to any [alignment] transformation, so in this + /// example, the child is rotated about its center, since [alignment] + /// in [Transform.rotate] defaults to [Alignment.center]: + /// + /// ```dart + /// Transform.rotate( + /// angle: math.pi, + /// child: Container( + /// width: 150.0, + /// height: 150.0, + /// color: Colors.blue, + /// ), + /// ) + /// ``` + /// + /// However, in this example the [origin] offset is applied after the + /// `alignment`, so the child rotates about its bottom-right corner: + /// + /// ```dart + /// Transform.rotate( + /// angle: math.pi, + /// origin: const Offset(75.0, 75.0), + /// child: Container( + /// width: 150.0, + /// height: 150.0, + /// color: Colors.blue, + /// ), + /// ) + /// ``` final Offset? origin; /// The alignment of the origin, relative to the size of the box. /// + /// When this and [origin] are both null, the origin is the upper-left corner + /// of this render object. + /// The default for this field is null for some constructors, + /// and [Alignment.center] for others. + /// /// This is equivalent to setting an origin based on the size of the box. /// If it is specified at the same time as the [origin], both are applied. ///