Skip to content

Commit 963511f

Browse files
Add directional static members to AlignmentGeometry. (flutter#176571)
Closes flutter#176543 - Adds `topStart`, `topEnd`, `centerStart`, `centerEnd`, `bottomStart`, and `bottomEnd` constants to `AlignmentGeometry` to enable `AlignmentDirectional` quick usage with dot shorthand syntax ## 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
1 parent 0fcbded commit 963511f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

packages/flutter/lib/src/painting/alignment.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ abstract class AlignmentGeometry {
5454
/// * [Alignment.topRight], which is the same thing.
5555
static const AlignmentGeometry topRight = Alignment.topRight;
5656

57+
/// The top corner on the "start" edge.
58+
///
59+
/// {@template flutter.painting.alignment.directional.start}
60+
/// This can be used to indicate an offset from the left in [TextDirection.ltr]
61+
/// text and an offset from the right in [TextDirection.rtl] text without having
62+
/// to be aware of the current text direction.
63+
/// {@endtemplate}
64+
///
65+
/// See also:
66+
///
67+
/// * [AlignmentDirectional.topStart], which is the same thing.
68+
static const AlignmentGeometry topStart = AlignmentDirectional.topStart;
69+
70+
/// The top corner on the "end" edge.
71+
///
72+
/// {@template flutter.painting.alignment.directional.end}
73+
/// This can be used to indicate an offset from the right in [TextDirection.ltr]
74+
/// text and an offset from the left in [TextDirection.rtl] text without having
75+
/// to be aware of the current text direction.
76+
/// {@endtemplate}
77+
///
78+
/// See also:
79+
///
80+
/// * [AlignmentDirectional.topEnd], which is the same thing.
81+
static const AlignmentGeometry topEnd = AlignmentDirectional.topEnd;
82+
5783
/// The center point along the left edge.
5884
///
5985
/// See also:
@@ -75,6 +101,24 @@ abstract class AlignmentGeometry {
75101
/// * [Alignment.centerRight], which is the same thing.
76102
static const AlignmentGeometry centerRight = Alignment.centerRight;
77103

104+
/// The center point along the "start" edge.
105+
///
106+
/// {@macro flutter.painting.alignment.directional.start}
107+
///
108+
/// See also:
109+
///
110+
/// * [AlignmentDirectional.centerStart], which is the same thing.
111+
static const AlignmentGeometry centerStart = AlignmentDirectional.centerStart;
112+
113+
/// The center point along the "end" edge.
114+
///
115+
/// {@macro flutter.painting.alignment.directional.end}
116+
///
117+
/// See also:
118+
///
119+
/// * [AlignmentDirectional.centerEnd], which is the same thing.
120+
static const AlignmentGeometry centerEnd = AlignmentDirectional.centerEnd;
121+
78122
/// The bottom left corner.
79123
///
80124
/// See also:
@@ -96,6 +140,24 @@ abstract class AlignmentGeometry {
96140
/// * [Alignment.bottomRight], which is the same thing.
97141
static const AlignmentGeometry bottomRight = Alignment.bottomRight;
98142

143+
/// The bottom corner on the "start" edge.
144+
///
145+
/// {@macro flutter.painting.alignment.directional.start}
146+
///
147+
/// See also:
148+
///
149+
/// * [AlignmentDirectional.bottomStart], which is the same thing.
150+
static const AlignmentGeometry bottomStart = AlignmentDirectional.bottomStart;
151+
152+
/// The bottom corner on the "end" edge.
153+
///
154+
/// {@macro flutter.painting.alignment.directional.end}
155+
///
156+
/// See also:
157+
///
158+
/// * [AlignmentDirectional.bottomEnd], which is the same thing.
159+
static const AlignmentGeometry bottomEnd = AlignmentDirectional.bottomEnd;
160+
99161
double get _x;
100162

101163
double get _start;

packages/flutter/test/painting/alignment_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,18 @@ void main() {
344344
expect(AlignmentGeometry.topLeft, Alignment.topLeft);
345345
expect(AlignmentGeometry.topCenter, Alignment.topCenter);
346346
expect(AlignmentGeometry.topRight, Alignment.topRight);
347+
expect(AlignmentGeometry.topStart, AlignmentDirectional.topStart);
348+
expect(AlignmentGeometry.topEnd, AlignmentDirectional.topEnd);
347349
expect(AlignmentGeometry.centerLeft, Alignment.centerLeft);
348350
expect(AlignmentGeometry.center, Alignment.center);
349351
expect(AlignmentGeometry.centerRight, Alignment.centerRight);
352+
expect(AlignmentGeometry.centerStart, AlignmentDirectional.centerStart);
353+
expect(AlignmentGeometry.centerEnd, AlignmentDirectional.centerEnd);
350354
expect(AlignmentGeometry.bottomLeft, Alignment.bottomLeft);
351355
expect(AlignmentGeometry.bottomCenter, Alignment.bottomCenter);
352356
expect(AlignmentGeometry.bottomRight, Alignment.bottomRight);
357+
expect(AlignmentGeometry.bottomStart, AlignmentDirectional.bottomStart);
358+
expect(AlignmentGeometry.bottomEnd, AlignmentDirectional.bottomEnd);
353359
});
354360

355361
test('AlignmentDirectional.resolve with null TextDirection asserts', () {

0 commit comments

Comments
 (0)