From 51cd8b67999247b01543dcc184cbc2f90483e5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Tiselice?= Date: Fri, 16 Sep 2016 15:59:01 -0700 Subject: [PATCH] Added a stretch Positioned constructor. (#5894) Fixes #5835. --- dev/manual_tests/card_collection.dart | 6 +----- examples/flutter_gallery/lib/demo/cards_demo.dart | 6 +----- packages/flutter/lib/src/material/grid_tile.dart | 6 +----- packages/flutter/lib/src/material/tooltip.dart | 6 +----- packages/flutter/lib/src/widgets/basic.dart | 13 +++++++++++++ 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/dev/manual_tests/card_collection.dart b/dev/manual_tests/card_collection.dart index cdbd500311..25e0e40db2 100644 --- a/dev/manual_tests/card_collection.dart +++ b/dev/manual_tests/card_collection.dart @@ -363,11 +363,7 @@ class CardCollectionState extends State { // size of the background,card Stack will be based only on the card. The // Viewport ensures that when the card's resize animation occurs, the // background (text and icons) will just be clipped, not resized. - Widget background = new Positioned( - top: 0.0, - right: 0.0, - bottom: 0.0, - left: 0.0, + Widget background = new Positioned.stretch( child: new Container( margin: const EdgeInsets.all(4.0), child: new Viewport( diff --git a/examples/flutter_gallery/lib/demo/cards_demo.dart b/examples/flutter_gallery/lib/demo/cards_demo.dart index 61b71c7961..41a28faaa8 100644 --- a/examples/flutter_gallery/lib/demo/cards_demo.dart +++ b/examples/flutter_gallery/lib/demo/cards_demo.dart @@ -61,11 +61,7 @@ class TravelDestinationItem extends StatelessWidget { height: 184.0, child: new Stack( children: [ - new Positioned( - left: 0.0, - top: 0.0, - bottom: 0.0, - right: 0.0, + new Positioned.stretch( child: new Image.asset( destination.assetName, fit: ImageFit.cover diff --git a/packages/flutter/lib/src/material/grid_tile.dart b/packages/flutter/lib/src/material/grid_tile.dart index 7e07a36cee..cbbb1e9f99 100644 --- a/packages/flutter/lib/src/material/grid_tile.dart +++ b/packages/flutter/lib/src/material/grid_tile.dart @@ -38,11 +38,7 @@ class GridTile extends StatelessWidget { return child; final List children = [ - new Positioned( - top: 0.0, - left: 0.0, - bottom: 0.0, - right: 0.0, + new Positioned.stretch( child: child ) ]; diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index 9849f69218..8cea208035 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -265,11 +265,7 @@ class _TooltipOverlay extends StatelessWidget { @override Widget build(BuildContext context) { - return new Positioned( - top: 0.0, - left: 0.0, - right: 0.0, - bottom: 0.0, + return new Positioned.stretch( child: new IgnorePointer( child: new CustomSingleChildLayout( delegate: new _TooltipPositionDelegate( diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index d76e3051f0..62ba487bb3 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -1517,6 +1517,19 @@ class Positioned extends ParentDataWidget { bottom = null, super(key: key, child: child); + /// Creates a Positioned object with [left], [top], [right], and [bottom] set + /// to 0.0 unless a value for them is passed. + Positioned.stretch({ + Key key, + Widget child, + this.left: 0.0, + this.top: 0.0, + this.right: 0.0, + this.bottom: 0.0 + }) : width = null, + height = null, + super(key: key, child: child); + /// The distance that the child's left edge is inset from the left of the stack. /// /// Only two out of the three horizontal values ([left], [right], [width]) can be