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