Commit 0044ea2d authored by Adam Barth's avatar Adam Barth Committed by GitHub

Replace usage of FractionalOffset with Alignment (#12348)

Alignment will eventually replace FractionalOffset.
parent 2b126bcd
......@@ -44,7 +44,7 @@ class _MyHomePageState extends State<MyHomePage> {
return new Scaffold(
body: new Stack(
fit: StackFit.expand,
alignment: FractionalOffset.bottomCenter,
alignment: Alignment.bottomCenter,
children: <Widget>[
new LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
......
......@@ -224,7 +224,7 @@ class CardCollectionState extends State<CardCollection> {
flexibleSpace: new Container(
padding: const EdgeInsets.only(left: 72.0),
height: 128.0,
alignment: const FractionalOffset(0.0, 0.75),
alignment: const Alignment(-1.0, 0.5),
child: new Text('Swipe Away: ${_cardModels.length}', style: Theme.of(context).primaryTextTheme.title),
),
);
......@@ -330,8 +330,8 @@ class CardCollectionState extends State<CardCollection> {
Shader _createShader(Rect bounds) {
return new LinearGradient(
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomLeft,
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35],
)
......
......@@ -64,8 +64,8 @@ class GradientRow extends StatelessWidget {
height: 100.0,
decoration: new BoxDecoration(
gradient: new LinearGradient(
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomRight,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[ leftColor, rightColor ],
),
),
......
......@@ -55,7 +55,7 @@ class _AppBarBottomSampleState extends State<AppBarBottomSample> with SingleTick
data: Theme.of(context).copyWith(accentColor: Colors.white),
child: new Container(
height: 48.0,
alignment: FractionalOffset.center,
alignment: Alignment.center,
child: new TabPageSelector(controller: _tabController),
),
),
......
......@@ -169,7 +169,7 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
this.selectedIndex,
});
final FractionalOffset translation;
final Alignment translation;
final double tColumnToRow;
final double tCollapsed;
final int cardCount;
......@@ -349,7 +349,7 @@ class _AllSectionsView extends AnimatedWidget {
return new CustomMultiChildLayout(
delegate: new _AllSectionsLayout(
translation: new FractionalOffset(selectedIndex.value - sectionIndex, 0.0),
translation: new Alignment((selectedIndex.value - sectionIndex) * 2.0 - 1.0, -1.0),
tColumnToRow: tColumnToRow,
tCollapsed: tCollapsed,
cardCount: sections.length,
......
......@@ -25,8 +25,8 @@ class SectionCard extends StatelessWidget {
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(4.0),
gradient: new LinearGradient(
begin: FractionalOffset.topLeft,
end: FractionalOffset.topRight,
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[
section.leftColor,
section.rightColor,
......@@ -82,7 +82,7 @@ class SectionTitle extends StatelessWidget {
opacity: opacity,
child: new Transform(
transform: new Matrix4.identity()..scale(scale),
alignment: FractionalOffset.center,
alignment: Alignment.center,
child: new Stack(
children: <Widget>[
new Positioned(
......@@ -136,7 +136,7 @@ class SectionDetailView extends StatelessWidget {
package: detail.imageAssetPackage,
),
fit: BoxFit.cover,
alignment: FractionalOffset.center,
alignment: Alignment.center,
),
),
);
......
......@@ -166,8 +166,8 @@ class ContactsDemoState extends State<ContactsDemo> {
const DecoratedBox(
decoration: const BoxDecoration(
gradient: const LinearGradient(
begin: const FractionalOffset(0.5, 0.0),
end: const FractionalOffset(0.5, 0.30),
begin: const Alignment(0.0, -1.0),
end: const Alignment(0.0, -0.4),
colors: const <Color>[const Color(0x60000000), const Color(0x00000000)],
),
),
......
......@@ -39,7 +39,7 @@ class _CupertinoButtonDemoState extends State<CupertinoButtonsDemo> {
: ' '),
const Padding(padding: const EdgeInsets.all(12.0)),
new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......
......@@ -47,9 +47,9 @@ class NavigationIconView {
return new FadeTransition(
opacity: _animation,
child: new SlideTransition(
position: new FractionalOffsetTween(
begin: const FractionalOffset(0.0, 0.02), // Small offset from the top.
end: FractionalOffset.topLeft,
position: new AlignmentTween(
begin: const Alignment(0.0, 0.4), // Slightly down.
end: Alignment.center,
).animate(_animation),
child: new IconTheme(
data: new IconThemeData(
......
......@@ -90,7 +90,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildRaisedButton() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -111,7 +111,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildFlatButton() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -213,7 +213,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildIconButton() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -237,7 +237,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildActionButton() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () {
......
......@@ -85,7 +85,7 @@ class TravelDestinationItem extends StatelessWidget {
right: 16.0,
child: new FittedBox(
fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
child: new Text(destination.title,
style: titleStyle,
),
......
......@@ -25,7 +25,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
AnimationController _controller;
Animation<double> _drawerContentsOpacity;
Animation<FractionalOffset> _drawerDetailsPosition;
Animation<Alignment> _drawerDetailsPosition;
bool _showDrawerContents = true;
@override
......@@ -39,9 +39,9 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
parent: new ReverseAnimation(_controller),
curve: Curves.fastOutSlowIn,
);
_drawerDetailsPosition = new FractionalOffsetTween(
begin: const FractionalOffset(0.0, -1.0),
end: const FractionalOffset(0.0, 0.0),
_drawerDetailsPosition = new AlignmentTween(
begin: const Alignment(0.0, -2.0),
end: Alignment.center,
).animate(new CurvedAnimation(
parent: _controller,
curve: Curves.fastOutSlowIn,
......@@ -80,7 +80,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(_backIcon()),
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
tooltip: 'Back',
onPressed: () {
Navigator.pop(context);
......
......@@ -51,7 +51,7 @@ class DualHeaderWithHint extends StatelessWidget {
margin: const EdgeInsets.only(left: 24.0),
child: new FittedBox(
fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
child: new Text(
name,
style: textTheme.body1.copyWith(fontSize: 15.0),
......
......@@ -165,7 +165,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
decoration: new BoxDecoration(
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
),
alignment: FractionalOffset.bottomLeft,
alignment: Alignment.bottomLeft,
child: new Text('Event name', style: theme.textTheme.display2)
),
new Container(
......@@ -173,7 +173,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
decoration: new BoxDecoration(
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
),
alignment: FractionalOffset.bottomLeft,
alignment: Alignment.bottomLeft,
child: new Text('Location', style: theme.textTheme.title.copyWith(color: Colors.black54))
),
new Column(
......
......@@ -54,7 +54,7 @@ class _GridTitleText extends StatelessWidget {
Widget build(BuildContext context) {
return new FittedBox(
fit: BoxFit.scaleDown,
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
child: new Text(text),
);
}
......
......@@ -75,7 +75,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
Widget buildCheckbox() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -109,7 +109,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
Widget buildRadio() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -161,7 +161,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
Widget buildSwitch() {
return new Align(
alignment: const FractionalOffset(0.5, 0.4),
alignment: const Alignment(0.0, -0.2),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......
......@@ -107,8 +107,8 @@ class _CardDataItem extends StatelessWidget {
children: <Widget>[
new Align(
alignment: page.id == 'L'
? FractionalOffset.centerLeft
: FractionalOffset.centerRight,
? Alignment.centerLeft
: Alignment.centerRight,
child: new CircleAvatar(child: new Text('${page.id}')),
),
new SizedBox(
......
......@@ -188,7 +188,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
),
new Container(
padding: const EdgeInsets.all(20.0),
alignment: const FractionalOffset(0.5, 0.5),
alignment: Alignment.center,
child: new RaisedButton(
child: const Text('SUBMIT'),
onPressed: _handleSubmitted,
......
......@@ -211,7 +211,7 @@ class _PestoLogoState extends State<PestoLogo> {
Widget build(BuildContext context) {
return new Transform(
transform: new Matrix4.identity()..scale(widget.height / kLogoHeight),
alignment: FractionalOffset.topCenter,
alignment: Alignment.topCenter,
child: new SizedBox(
width: kLogoWidth,
child: new Stack(
......@@ -362,8 +362,8 @@ class _RecipePageState extends State<RecipePage> {
background: new DecoratedBox(
decoration: new BoxDecoration(
gradient: new LinearGradient(
begin: const FractionalOffset(0.5, 0.0),
end: const FractionalOffset(0.5, 0.40),
begin: const Alignment(0.0, -1.0),
end: const Alignment(0.0, -0.2),
colors: <Color>[const Color(0x60000000), const Color(0x00000000)],
),
),
......@@ -450,7 +450,7 @@ class RecipeSheet extends StatelessWidget {
package: recipe.ingredientsImagePackage,
width: 32.0,
height: 32.0,
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
fit: BoxFit.scaleDown
)
),
......
......@@ -320,7 +320,7 @@ class _ProductItem extends StatelessWidget {
new Column(
children: <Widget>[
new Align(
alignment: FractionalOffset.centerRight,
alignment: Alignment.centerRight,
child: new _ProductPriceItem(product: product),
),
new Container(
......
......@@ -85,7 +85,7 @@ class _VendorItem extends StatelessWidget {
new SizedBox(
height: 24.0,
child: new Align(
alignment: FractionalOffset.bottomLeft,
alignment: Alignment.bottomLeft,
child: new Text(vendor.name, style: theme.vendorTitleStyle),
),
),
......@@ -174,7 +174,7 @@ class _Heading extends StatelessWidget {
product.imageAsset,
package: product.imageAssetPackage,
fit: BoxFit.contain,
alignment: FractionalOffset.center,
alignment: Alignment.center,
),
),
),
......
......@@ -138,7 +138,7 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
child: new Container(
height: 48.0,
padding: const EdgeInsets.only(left: 16.0),
alignment: FractionalOffset.centerLeft,
alignment: Alignment.centerLeft,
child: new Text(galleryItem.category, style: headerStyle)
),
)
......
......@@ -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: FractionalOffset.center,
alignment: Alignment.center,
// We use a RenderParagraph to display the text 'Hello, world.' without
// any explicit styling.
child: new RenderParagraph(
......
......@@ -34,12 +34,12 @@ void main() {
// spin.
final RenderTransform spin = new RenderTransform(
transform: new Matrix4.identity(),
alignment: FractionalOffset.center,
alignment: Alignment.center,
child: square
);
// Finally, we center the spinning green square...
final RenderBox root = new RenderPositionedBox(
alignment: FractionalOffset.center,
alignment: Alignment.center,
child: spin
);
// and attach it to the window.
......
......@@ -100,7 +100,7 @@ void main() {
flexRoot.add(proxy);
addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1);
transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity(), alignment: FractionalOffset.center);
transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity(), alignment: Alignment.center);
final RenderPadding root = new RenderPadding(padding: const EdgeInsets.all(80.0), child: transformBox);
binding.renderView.child = root;
......
......@@ -14,14 +14,14 @@ void approxExpect(Alignment a, Alignment b) {
void main() {
test('Alignment control test', () {
const Alignment offset = const Alignment(0.5, 0.25);
const Alignment alignment = const Alignment(0.5, 0.25);
expect(offset, hasOneLineDescription);
expect(offset.hashCode, equals(const Alignment(0.5, 0.25).hashCode));
expect(alignment, hasOneLineDescription);
expect(alignment.hashCode, equals(const Alignment(0.5, 0.25).hashCode));
expect(offset / 2.0, const Alignment(0.25, 0.125));
expect(offset ~/ 2.0, const Alignment(0.0, 0.0));
expect(offset % 5.0, const Alignment(0.5, 0.25));
expect(alignment / 2.0, const Alignment(0.25, 0.125));
expect(alignment ~/ 2.0, const Alignment(0.0, 0.0));
expect(alignment % 5.0, const Alignment(0.5, 0.25));
});
test('Alignment.lerp()', () {
......
......@@ -290,7 +290,7 @@ abstract class Finder {
///
/// The [at] parameter specifies the location relative to the size of the
/// target element where the hit test is performed.
Finder hitTestable({ FractionalOffset at: FractionalOffset.center }) => new _HitTestableFinder(this, at);
Finder hitTestable({ Alignment at: Alignment.center }) => new _HitTestableFinder(this, at);
@override
String toString() {
......@@ -336,10 +336,10 @@ class _LastFinder extends Finder {
}
class _HitTestableFinder extends Finder {
_HitTestableFinder(this.parent, this.offset);
_HitTestableFinder(this.parent, this.alignment);
final Finder parent;
final FractionalOffset offset;
final Alignment alignment;
@override
String get description => '${parent.description} (considering only hit-testable ones)';
......@@ -349,7 +349,7 @@ class _HitTestableFinder extends Finder {
for (final Element candidate in parent.apply(candidates)) {
final RenderBox box = candidate.renderObject;
assert(box != null);
final Offset absoluteOffset = box.localToGlobal(offset.alongSize(box.size));
final Offset absoluteOffset = box.localToGlobal(alignment.alongSize(box.size));
final HitTestResult hitResult = new HitTestResult();
WidgetsBinding.instance.hitTest(hitResult, absoluteOffset);
for (final HitTestEntry entry in hitResult.path) {
......
......@@ -29,7 +29,7 @@ void main() {
)),
);
expect(find.byType(GestureDetector), findsNWidgets(2));
final Finder hitTestable = find.byType(GestureDetector).hitTestable(at: const FractionalOffset(0.5, 0.5));
final Finder hitTestable = find.byType(GestureDetector).hitTestable(at: Alignment.center);
expect(hitTestable, findsOneWidget);
expect(tester.widget(hitTestable).key, const ValueKey<int>(0));
});
......
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