Commit 1ba539a6 authored by Adam Barth's avatar Adam Barth

Add constants for FractionalOffsets

Adds some names for common FractionalOffset values.
parent 055268ea
......@@ -397,8 +397,8 @@ class CardCollectionState extends State<CardCollection> {
Shader _createShader(Rect bounds) {
return new LinearGradient(
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.0, 1.0),
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomLeft,
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35]
)
......@@ -441,7 +441,7 @@ class CardCollectionState extends State<CardCollection> {
if (_snapToCenter) {
Widget indicator = new IgnorePointer(
child: new Align(
alignment: const FractionalOffset(0.0, 0.5),
alignment: FractionalOffset.centerLeft,
child: new Container(
height: 1.0,
decoration: new BoxDecoration(backgroundColor: const Color(0x80FFFFFF))
......
......@@ -13,7 +13,7 @@ void main() {
// The root of our render tree is a RenderPositionedBox, which centers its
// child both vertically and horizontally.
root: new RenderPositionedBox(
alignment: const FractionalOffset(0.5, 0.5),
alignment: FractionalOffset.center,
// We use a RenderParagraph to display the text 'Hello, world.' without
// any explicit styling.
child: new RenderParagraph(new TextSpan(text: 'Hello, world.'))
......
......@@ -27,12 +27,12 @@ void main() {
// spin.
RenderTransform spin = new RenderTransform(
transform: new Matrix4.identity(),
alignment: const FractionalOffset(0.5, 0.5),
alignment: FractionalOffset.center,
child: square
);
// Finally, we center the spinning green square...
RenderBox root = new RenderPositionedBox(
alignment: const FractionalOffset(0.5, 0.5),
alignment: FractionalOffset.center,
child: spin
);
// and attach it to the window.
......
......@@ -172,7 +172,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
),
child: new Align(
alignment: const FractionalOffset(0.0, 1.0),
alignment: FractionalOffset.bottomLeft,
child: new Text('Event name', style: theme.textTheme.display2)
)
),
......@@ -182,7 +182,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
),
child: new Align(
alignment: const FractionalOffset(0.0, 1.0),
alignment: FractionalOffset.bottomLeft,
child: new Text('Location', style: theme.textTheme.title.copyWith(color: Colors.black54))
)
),
......
......@@ -285,8 +285,8 @@ class GradientNode extends NodeWithSize {
Rect rect = Point.origin & size;
Paint gradientPaint = new Paint()..shader = new LinearGradient(
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.0, 1.0),
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomLeft,
colors: <Color>[colorTop, colorBottom],
stops: <double>[0.0, 1.0]
).createShader(rect);
......
......@@ -187,7 +187,7 @@ class AppBar extends StatelessWidget {
padding: new EdgeInsets.only(left: combinedPadding.left, right: combinedPadding.right),
child: new ClipRect(
child: new OverflowBox(
alignment: const FractionalOffset(0.0, 1.0), // bottom justify
alignment: FractionalOffset.bottomLeft, // bottom justify
minHeight: paddedCollapsedHeight,
maxHeight: paddedCollapsedHeight,
child: new Padding(
......@@ -203,7 +203,7 @@ class AppBar extends StatelessWidget {
appBar = new Stack(
children: <Widget>[
flexibleSpace(context),
new Align(child: appBar, alignment: const FractionalOffset(0.0, 0.0))
new Align(child: appBar, alignment: FractionalOffset.topLeft)
]
);
}
......
......@@ -178,7 +178,7 @@ class DrawerControllerState extends State<DrawerController> {
Widget build(BuildContext context) {
if (_controller.status == AnimationStatus.dismissed) {
return new Align(
alignment: const FractionalOffset(0.0, 0.5),
alignment: FractionalOffset.centerLeft,
child: new GestureDetector(
key: _gestureDetectorKey,
onHorizontalDragUpdate: _move,
......@@ -208,9 +208,9 @@ class DrawerControllerState extends State<DrawerController> {
)
),
new Align(
alignment: const FractionalOffset(0.0, 0.5),
alignment: FractionalOffset.centerLeft,
child: new Align(
alignment: const FractionalOffset(1.0, 0.5),
alignment: FractionalOffset.centerRight,
widthFactor: _controller.value,
child: new RepaintBoundary(
child: new Focus(
......
......@@ -322,7 +322,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
children: config.items,
key: indexedStackKey,
index: _selectedIndex,
alignment: const FractionalOffset(0.5, 0.0)
alignment: FractionalOffset.topCenter
),
new Container(
child: new Icon(icon: Icons.arrow_drop_down, size: 36.0),
......
......@@ -81,7 +81,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
end: new FractionalOffset(0.0, yAlignEnd)
).evaluate(scaleAndAlignCurve),
child: new ScaleTransition(
alignment: const FractionalOffset(0.0, 1.0),
alignment: FractionalOffset.bottomLeft,
scale: new Tween<double>(begin: 1.5, end: 1.0).animate(scaleAndAlignCurve),
child: new Align(
alignment: new FractionalOffset(0.0, 1.0),
......
......@@ -236,7 +236,7 @@ class _PopupMenu<T> extends StatelessWidget {
type: MaterialType.card,
elevation: route.elevation,
child: new Align(
alignment: const FractionalOffset(1.0, 0.0),
alignment: FractionalOffset.topRight,
widthFactor: width.evaluate(route.animation),
heightFactor: height.evaluate(route.animation),
child: child
......
......@@ -534,7 +534,7 @@ class ScaffoldState extends State<Scaffold> {
bottomSheets.add(_currentBottomSheet._widget);
Widget stack = new Stack(
children: bottomSheets,
alignment: const FractionalOffset(0.5, 1.0) // bottom-aligned, centered
alignment: FractionalOffset.bottomCenter
);
_addIfNonNull(children, stack, _ScaffoldSlot.bottomSheet);
}
......@@ -661,7 +661,7 @@ class _PersistentBottomSheetState extends State<_PersistentBottomSheet> {
animation: config.animationController,
builder: (BuildContext context, Widget child) {
return new Align(
alignment: const FractionalOffset(0.0, 0.0),
alignment: FractionalOffset.topLeft,
heightFactor: config.animationController.value,
child: child
);
......
......@@ -111,7 +111,7 @@ class SnackBar extends StatelessWidget {
animation: heightAnimation,
builder: (BuildContext context, Widget child) {
return new Align(
alignment: const FractionalOffset(0.0, 0.0),
alignment: FractionalOffset.topLeft,
heightFactor: heightAnimation.value,
child: child
);
......
......@@ -481,8 +481,8 @@ abstract class Gradient {
/// A 2D linear gradient.
class LinearGradient extends Gradient {
const LinearGradient({
this.begin: const FractionalOffset(0.0, 0.5),
this.end: const FractionalOffset(1.0, 0.5),
this.begin: FractionalOffset.centerLeft,
this.end: FractionalOffset.centerRight,
this.colors,
this.stops,
this.tileMode: TileMode.clamp
......@@ -570,7 +570,7 @@ class LinearGradient extends Gradient {
/// A 2D radial gradient.
class RadialGradient extends Gradient {
const RadialGradient({
this.center: const FractionalOffset(0.5, 0.5),
this.center: FractionalOffset.center,
this.radius: 0.5,
this.colors,
this.stops,
......@@ -856,7 +856,18 @@ class FractionalOffset {
final double dx;
final double dy;
static const FractionalOffset zero = const FractionalOffset(0.0, 0.0);
static const FractionalOffset topLeft = const FractionalOffset(0.0, 0.0);
static const FractionalOffset topCenter = const FractionalOffset(0.5, 0.0);
static const FractionalOffset topRight = const FractionalOffset(1.0, 0.0);
static const FractionalOffset bottomLeft = const FractionalOffset(0.0, 1.0);
static const FractionalOffset bottomCenter = const FractionalOffset(0.5, 1.0);
static const FractionalOffset bottomRight = const FractionalOffset(1.0, 1.0);
static const FractionalOffset centerLeft = const FractionalOffset(0.0, 0.5);
static const FractionalOffset centerRight = const FractionalOffset(1.0, 0.5);
static const FractionalOffset center = const FractionalOffset(0.5, 0.5);
FractionalOffset operator -() {
return new FractionalOffset(-dx, -dy);
......
......@@ -201,7 +201,7 @@ abstract class RenderStackBase extends RenderBox
RenderBoxContainerDefaultsMixin<RenderBox, StackParentData> {
RenderStackBase({
List<RenderBox> children,
FractionalOffset alignment: const FractionalOffset(0.0, 0.0)
FractionalOffset alignment: FractionalOffset.topLeft
}) : _alignment = alignment {
addAll(children);
}
......@@ -440,7 +440,7 @@ abstract class RenderStackBase extends RenderBox
class RenderStack extends RenderStackBase {
RenderStack({
List<RenderBox> children,
FractionalOffset alignment: const FractionalOffset(0.0, 0.0)
FractionalOffset alignment: FractionalOffset.topLeft
}) : super(
children: children,
alignment: alignment
......@@ -460,7 +460,7 @@ class RenderStack extends RenderStackBase {
class RenderIndexedStack extends RenderStackBase {
RenderIndexedStack({
List<RenderBox> children,
FractionalOffset alignment: const FractionalOffset(0.0, 0.0),
FractionalOffset alignment: FractionalOffset.topLeft,
int index: 0
}) : _index = index, super(
children: children,
......
......@@ -191,7 +191,7 @@ class _DismissableState extends State<Dismissable> {
void _updateMoveAnimation() {
_moveAnimation = new Tween<FractionalOffset>(
begin: FractionalOffset.zero,
begin: FractionalOffset.topLeft,
end: _directionIsXAxis ?
new FractionalOffset(_dragExtent.sign, 0.0) :
new FractionalOffset(0.0, _dragExtent.sign)
......
......@@ -121,7 +121,7 @@ class ScaleTransition extends AnimatedWidget {
ScaleTransition({
Key key,
Animation<double> scale,
this.alignment: const FractionalOffset(0.5, 0.5),
this.alignment: FractionalOffset.center,
this.child
}) : scale = scale, super(key: key, animation: scale);
......@@ -177,7 +177,7 @@ class RotationTransition extends AnimatedWidget {
Matrix4 transform = new Matrix4.rotationZ(turnsValue * math.PI * 2.0);
return new Transform(
transform: transform,
alignment: const FractionalOffset(0.5, 0.5),
alignment: FractionalOffset.center,
child: child
);
}
......
......@@ -14,7 +14,7 @@ void main() {
decoration: new BoxDecoration(
backgroundColor: const Color(0xFF00FF00),
gradient: new RadialGradient(
center: FractionalOffset.zero, radius: 1.8,
center: FractionalOffset.topLeft, radius: 1.8,
colors: <Color>[Colors.yellow[500], Colors.blue[500]]),
boxShadow: elevationToShadow[3])
);
......
......@@ -10,12 +10,11 @@ import 'package:test/test.dart';
Shader createShader(Rect bounds) {
return new LinearGradient(
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.0, 1.0),
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35]
)
.createShader(bounds);
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomLeft,
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35]
).createShader(bounds);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment