mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add convenience static members to AlignmentGeometry (#169709)
This adds convenience members to `AlignmentGeometry` in preparation for
Dart shorthands.
Before:
```dart
Container(
alignment: Alignment.topLeft,
child: Text('Hello world'),
),
```
After (with Dart shorthands):
```dart
Container(
alignment: .topLeft,
child: Text('Hello world'),
),
```
Prior art: https://github.com/flutter/flutter/pull/165597
## 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].
- [ ] 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.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
<!-- 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
This commit is contained in:
parent
a79827a310
commit
34656ff29a
@ -15,8 +15,8 @@ import 'basic_types.dart';
|
||||
/// Base class for [Alignment] that allows for text-direction aware
|
||||
/// resolution.
|
||||
///
|
||||
/// A property or argument of this type accepts classes created either with [
|
||||
/// Alignment] and its variants, or [AlignmentDirectional.new].
|
||||
/// A property or argument of this type accepts classes created either with
|
||||
/// [Alignment] and its variants, or [AlignmentDirectional.new].
|
||||
///
|
||||
/// To convert an [AlignmentGeometry] object of indeterminate type into an
|
||||
/// [Alignment] object, call the [resolve] method.
|
||||
@ -32,6 +32,69 @@ abstract class AlignmentGeometry {
|
||||
/// Creates a directional alignment, or [AlignmentDirectional].
|
||||
const factory AlignmentGeometry.directional(double start, double y) = AlignmentDirectional;
|
||||
|
||||
/// The top left corner.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.topLeft], which is the same thing.
|
||||
static const AlignmentGeometry topLeft = Alignment.topLeft;
|
||||
|
||||
/// The center point along the top edge.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.topCenter], which is the same thing.
|
||||
static const AlignmentGeometry topCenter = Alignment.topCenter;
|
||||
|
||||
/// The top right corner.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.topRight], which is the same thing.
|
||||
static const AlignmentGeometry topRight = Alignment.topRight;
|
||||
|
||||
/// The center point along the left edge.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.centerLeft], which is the same thing.
|
||||
static const AlignmentGeometry centerLeft = Alignment.centerLeft;
|
||||
|
||||
/// The center point, both horizontally and vertically.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.center], which is the same thing.
|
||||
static const AlignmentGeometry center = Alignment.center;
|
||||
|
||||
/// The center point along the right edge.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.centerRight], which is the same thing.
|
||||
static const AlignmentGeometry centerRight = Alignment.centerRight;
|
||||
|
||||
/// The bottom left corner.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.bottomLeft], which is the same thing.
|
||||
static const AlignmentGeometry bottomLeft = Alignment.bottomLeft;
|
||||
|
||||
/// The center point along the bottom edge.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.bottomCenter], which is the same thing.
|
||||
static const AlignmentGeometry bottomCenter = Alignment.bottomCenter;
|
||||
|
||||
/// The bottom right corner.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Alignment.bottomRight], which is the same thing.
|
||||
static const AlignmentGeometry bottomRight = Alignment.bottomRight;
|
||||
|
||||
double get _x;
|
||||
|
||||
double get _start;
|
||||
|
||||
@ -338,4 +338,16 @@ void main() {
|
||||
expect(const AlignmentGeometry.xy(4, 5), const Alignment(4, 5));
|
||||
expect(const AlignmentGeometry.directional(4, 5), const AlignmentDirectional(4, 5));
|
||||
});
|
||||
|
||||
test('AlignmentGeometry static members', () {
|
||||
expect(AlignmentGeometry.topLeft, Alignment.topLeft);
|
||||
expect(AlignmentGeometry.topCenter, Alignment.topCenter);
|
||||
expect(AlignmentGeometry.topRight, Alignment.topRight);
|
||||
expect(AlignmentGeometry.centerLeft, Alignment.centerLeft);
|
||||
expect(AlignmentGeometry.center, Alignment.center);
|
||||
expect(AlignmentGeometry.centerRight, Alignment.centerRight);
|
||||
expect(AlignmentGeometry.bottomLeft, Alignment.bottomLeft);
|
||||
expect(AlignmentGeometry.bottomCenter, Alignment.bottomCenter);
|
||||
expect(AlignmentGeometry.bottomRight, Alignment.bottomRight);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user