Generalize grid layout

This patch make grid layout much more flexible. The behavior is factored
out into a GridDelegate that's modeled after the custom layout
delegates. The patch includes a MaxTileWidthGridDelegate that implements
the old behavior and a FixedColumnCountGridDelegate that implements a
grid layout with a fixed number of columns.

Fixes #1048
This commit is contained in:
Adam Barth
2016-01-02 02:20:10 -08:00
parent a5925149d6
commit 46a178dce6
7 changed files with 478 additions and 91 deletions

View File

@@ -20,7 +20,10 @@ Color randomColor() {
RenderBox buildGridExample() {
List<RenderBox> children = new List<RenderBox>.generate(30, (_) => new RenderSolidColorBox(randomColor()));
return new RenderGrid(children: children, maxChildExtent: 100.0);
return new RenderGrid(
children: children,
delegate: new MaxTileWidthGridDelegate(maxTileWidth: 100.0)
);
}
main() => new RenderingFlutterBinding(root: buildGridExample());

View File

@@ -62,7 +62,7 @@ class AdaptiveItem {
}
class MediaQueryExample extends StatelessComponent {
static const double _maxChildExtent = 150.0;
static const double _maxTileWidth = 150.0;
static const double _gridViewBreakpoint = 450.0;
Widget _buildBody(BuildContext context) {
@@ -78,9 +78,9 @@ class MediaQueryExample extends StatelessComponent {
} else {
return new Block(
<Widget>[
new Grid(
new MaxTileWidthGrid(
items.map((AdaptiveItem item) => item.toCard()).toList(),
maxChildExtent: _maxChildExtent
maxTileWidth: _maxTileWidth
)
]
);