From 96d292fa0acd9d11e85fd04f7355a47cf3fb2723 Mon Sep 17 00:00:00 2001 From: Noaman Monther <83986256+devnoaman@users.noreply.github.com> Date: Thu, 19 Feb 2026 01:43:20 +0300 Subject: [PATCH] =?UTF-8?q?Fixing=20ExpansionTile=20expandedAlignment=20no?= =?UTF-8?q?t=20Accepts=20AlignmentGeometry=20=E2=80=A6=20(#180814)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *the expandedAlignment defined as Alignment , not as AlignmentGeometry even if _buildBody returns Align widget which accepts alignment property as AlignmentGeometry.* #180813 ## I have included 2 tests in the [flutter/tests] : 1- ExpansionTile expandedAlignment with directional test 2-ExpansionTile expandedCrossAxisAlignment with directional expandedAlignment test ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Victor Sanni Co-authored-by: Tong Mu --- .../lib/src/material/expansion_tile.dart | 2 +- .../test/material/expansion_tile_test.dart | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/expansion_tile.dart b/packages/flutter/lib/src/material/expansion_tile.dart index 41bae613676..874325f364d 100644 --- a/packages/flutter/lib/src/material/expansion_tile.dart +++ b/packages/flutter/lib/src/material/expansion_tile.dart @@ -272,7 +272,7 @@ class ExpansionTile extends StatefulWidget { /// /// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s /// [ExpansionTileThemeData]. - final Alignment? expandedAlignment; + final AlignmentGeometry? expandedAlignment; /// Specifies the alignment of each child within [children] when the tile is expanded. /// diff --git a/packages/flutter/test/material/expansion_tile_test.dart b/packages/flutter/test/material/expansion_tile_test.dart index e131cc5fe10..815e2449996 100644 --- a/packages/flutter/test/material/expansion_tile_test.dart +++ b/packages/flutter/test/material/expansion_tile_test.dart @@ -336,6 +336,40 @@ void main() { expect(columnRect.right, 100.0); }); + testWidgets('ExpansionTile expandedAlignment with directional test', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Directionality( + textDirection: TextDirection.rtl, + child: Material( + child: Center( + child: ExpansionTile( + title: Text('title'), + expandedAlignment: AlignmentDirectional.topEnd, + children: [ + SizedBox(height: 100, width: 100), + SizedBox(height: 100, width: 80), + ], + ), + ), + ), + ), + ), + ); + + await tester.tap(find.text('title')); + await tester.pumpAndSettle(); + + final Rect columnRect = tester.getRect(find.byType(Column).last); + + // The expandedAlignment is used to define the alignment of the Column widget in + // expanded tile, not the alignment of the children inside the Column. + expect(columnRect.left, 0.0); + // The width of the Column is the width of the largest child. The largest width + // being 100.0, the offset of the right edge of Column from X-axis should be 100.0. + expect(columnRect.right, 100.0); + }); + testWidgets('ExpansionTile expandedCrossAxisAlignment test', (WidgetTester tester) async { const child0Key = Key('child0'); const child1Key = Key('child1'); @@ -382,6 +416,57 @@ void main() { expect(child1Rect.left, 700.0); }); + testWidgets('ExpansionTile expandedCrossAxisAlignment with directional expandedAlignment test', ( + WidgetTester tester, + ) async { + const child0Key = Key('child0'); + const child1Key = Key('child1'); + + await tester.pumpWidget( + const MaterialApp( + home: Directionality( + textDirection: TextDirection.rtl, + child: Material( + child: Center( + child: ExpansionTile( + title: Text('title'), + // Set the column's alignment to AlignmentDirectional.centerStart to test CrossAxisAlignment + // of children widgets. This helps distinguish the effect of expandedAlignment + // and expandedCrossAxisAlignment later in the test. + expandedAlignment: AlignmentDirectional.centerStart, + expandedCrossAxisAlignment: CrossAxisAlignment.end, + children: [ + SizedBox(height: 100, width: 100, key: child0Key), + SizedBox(height: 100, width: 80, key: child1Key), + ], + ), + ), + ), + ), + ), + ); + + await tester.tap(find.text('title')); + await tester.pumpAndSettle(); + + final Rect columnRect = tester.getRect(find.byType(Column).last); + final Rect child0Rect = tester.getRect(find.byKey(child0Key)); + final Rect child1Rect = tester.getRect(find.byKey(child1Key)); + + // With `textDirection` set to `TextDirection.rtl`, `AlignmentDirectional.centerStart` + // resolves to `Alignment.centerRight`. The column of children should be aligned to the + // center right of the expanded tile. + expect(columnRect.right, 800.0); + // The width of the Column is the width of the largest child. The largest width + // being 100.0, the offset of the left edge of Column from X-axis should be 700.0. + expect(columnRect.left, 700.0); + + // With `textDirection` set to `TextDirection.rtl`, `CrossAxisAlignment.end` aligns children to the left. + // The offset of the left edge of both children from the X-axis should be 700.0. + expect(child0Rect.left, 700.0); + expect(child1Rect.left, 700.0); + }); + testWidgets('CrossAxisAlignment.baseline is not allowed', (WidgetTester tester) async { expect( () {