Fixing ExpansionTile expandedAlignment not Accepts AlignmentGeometry … (#180814)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

*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 <victorsanniay@gmail.com>
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
This commit is contained in:
Noaman Monther 2026-02-19 01:43:20 +03:00 committed by GitHub
parent 246b62f221
commit 96d292fa0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 86 additions and 1 deletions

View File

@ -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.
///

View File

@ -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: <Widget>[
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: <Widget>[
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(
() {