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