Commit fe01c71c authored by Adam Barth's avatar Adam Barth Committed by GitHub

Switch clients to ScrollGrid (#7752)

The only remaining client of ScrollableGrid (the old version) is Pesto,
which needs AppBar integration.
parent 41f1f8a4
......@@ -310,9 +310,6 @@ class GridListDemoState extends State<GridListDemo> {
});
}
// When the ScrollableGrid first appears we want the last row to only be
// partially visible, to help the user recognize that the grid is scrollable.
// The GridListDemoGridDelegate's tileHeightFactor is used for this.
@override
Widget build(BuildContext context) {
final Orientation orientation = MediaQuery.of(context).orientation;
......
......@@ -203,14 +203,12 @@ class GridLists {
// START gridlists
// Creates a scrollable grid list with images
// loaded from the web.
new ScrollableGrid(
delegate: new FixedColumnCountGridDelegate(
columnCount: 3,
tileAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0),
columnSpacing: 4.0,
rowSpacing: 4.0
),
new ScrollGrid.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: <String>[
'https://example.com/image-0.jpg',
'https://example.com/image-1.jpg',
......@@ -224,7 +222,7 @@ new ScrollableGrid(
),
child: new Image.network(url, fit: ImageFit.cover)
);
})
}).toList(),
);
// END
}
......
......@@ -76,14 +76,14 @@ class AdaptiveContainer extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) {
return new ScrollableList(
return new ScrollView(
itemExtent: _kListItemExtent,
children: names.map((String name) => new AdaptedListItem(name: name))
children: names.map((String name) => new AdaptedListItem(name: name)).toList(),
);
} else {
return new ScrollableGrid(
delegate: new MaxTileWidthGridDelegate(maxTileWidth: _kMaxTileWidth),
children: names.map((String name) => new AdaptedGridItem(name: name))
return new ScrollGrid.extent(
maxCrossAxisExtent: _kMaxTileWidth,
children: names.map((String name) => new AdaptedGridItem(name: name)).toList(),
);
}
}
......
......@@ -4,30 +4,41 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
/// A tile in a material design grid list.
///
/// A grid list is a [ScrollableGrid] of tiles in a vertical and horizontal
/// A grid list is a [ScrollGrid] of tiles in a vertical and horizontal
/// array. Each tile typically contains some visually rich content (e.g., an
/// image) together with a [GridTileBar] in either a [header] or a [footer].
///
/// See also:
///
/// * [ScrollableGrid]
/// * [GridTileBar]
/// * [ScrollGrid], which is a scrollable grid of tiles.
/// * [GridTileBar], which is typically used in either the [header] or
/// [footer].
/// * <https://material.google.com/components/grid-lists.html>
class GridTile extends StatelessWidget {
/// Creates a grid tile.
///
/// Must have a child. Does not typically have both a header and a footer.
GridTile({ Key key, this.header, this.footer, @required this.child }) : super(key: key) {
GridTile({
Key key,
this.header,
this.footer,
@required this.child,
}) : super(key: key) {
assert(child != null);
}
/// The widget to show over the top of this grid tile.
///
/// Typically a [GridTileBar].
final Widget header;
/// The widget to show over the bottom of this grid tile.
///
/// Typically a [GridTileBar].
final Widget footer;
/// The widget that fills the tile.
......
......@@ -28,7 +28,7 @@ class ScrollView extends StatelessWidget {
this.scrollDirection: Axis.vertical,
this.initialScrollOffset: 0.0,
this.itemExtent,
this.children,
this.children: const <Widget>[],
}) : super(key: key);
final EdgeInsets padding;
......@@ -76,7 +76,7 @@ class ScrollGrid extends StatelessWidget {
this.scrollDirection: Axis.vertical,
this.initialScrollOffset: 0.0,
this.gridDelegate,
this.children,
this.children: const <Widget>[],
}) : super(key: key);
ScrollGrid.count({
......@@ -88,7 +88,7 @@ class ScrollGrid extends StatelessWidget {
double mainAxisSpacing: 0.0,
double crossAxisSpacing: 0.0,
double childAspectRatio: 1.0,
this.children,
this.children: const <Widget>[],
}) : gridDelegate = new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
mainAxisSpacing: mainAxisSpacing,
......@@ -105,7 +105,7 @@ class ScrollGrid extends StatelessWidget {
double mainAxisSpacing: 0.0,
double crossAxisSpacing: 0.0,
double childAspectRatio: 1.0,
this.children,
this.children: const <Widget>[],
}) : gridDelegate = new SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxCrossAxisExtent,
mainAxisSpacing: mainAxisSpacing,
......
......@@ -7,30 +7,30 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
void main() {
testWidgets('ScrollableGrid default control', (WidgetTester tester) async {
await tester.pumpWidget(new Center(child: new ScrollableGrid(
delegate: new FixedColumnCountGridDelegate(columnCount: 1),
)));
testWidgets('ScrollGrid default control', (WidgetTester tester) async {
await tester.pumpWidget(new Center(
child: new ScrollGrid.count(
crossAxisCount: 1,
),
));
});
// Tests https://github.com/flutter/flutter/issues/5522
testWidgets('ScrollableGrid displays correct children with nonzero padding', (WidgetTester tester) async {
testWidgets('ScrollGrid displays correct children with nonzero padding', (WidgetTester tester) async {
final EdgeInsets padding = const EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0);
Widget testWidget = new Align(
child: new SizedBox(
height: 800.0,
width: 300.0, // forces the grid children to be 300..300
child: new ScrollableGrid(
delegate: new FixedColumnCountGridDelegate(
columnCount: 1,
padding: padding
),
child: new ScrollGrid.count(
crossAxisCount: 1,
padding: padding,
children: new List<Widget>.generate(10, (int index) {
return new Text('$index', key: new ValueKey<int>(index));
})
)
)
}).toList(),
),
),
);
await tester.pumpWidget(testWidget);
......
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