Commit ebe6da5b authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Rename BlockBody to ListBody. (#9291)

Nobody knew what a Block was.
parent f9ae2267
...@@ -170,7 +170,7 @@ class FancyImageItem extends StatelessWidget { ...@@ -170,7 +170,7 @@ class FancyImageItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new BlockBody( return new ListBody(
children: <Widget>[ children: <Widget>[
new UserHeader('Ali Connors $index'), new UserHeader('Ali Connors $index'),
new ItemDescription(), new ItemDescription(),
...@@ -193,7 +193,7 @@ class FancyGalleryItem extends StatelessWidget { ...@@ -193,7 +193,7 @@ class FancyGalleryItem extends StatelessWidget {
final int index; final int index;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new BlockBody( return new ListBody(
children: <Widget>[ children: <Widget>[
new UserHeader('Ali Connors'), new UserHeader('Ali Connors'),
new ItemGalleryBox(index), new ItemGalleryBox(index),
......
...@@ -266,7 +266,7 @@ class AboutDialog extends StatelessWidget { ...@@ -266,7 +266,7 @@ class AboutDialog extends StatelessWidget {
body.add(new Expanded( body.add(new Expanded(
child: new Padding( child: new Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0), padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: new BlockBody( child: new ListBody(
children: <Widget>[ children: <Widget>[
new Text(name, style: Theme.of(context).textTheme.headline), new Text(name, style: Theme.of(context).textTheme.headline),
new Text(version, style: Theme.of(context).textTheme.body1), new Text(version, style: Theme.of(context).textTheme.body1),
...@@ -286,7 +286,7 @@ class AboutDialog extends StatelessWidget { ...@@ -286,7 +286,7 @@ class AboutDialog extends StatelessWidget {
body.addAll(children); body.addAll(children);
return new AlertDialog( return new AlertDialog(
content: new SingleChildScrollView( content: new SingleChildScrollView(
child: new BlockBody(children: body), child: new ListBody(children: body),
), ),
actions: <Widget>[ actions: <Widget>[
new FlatButton( new FlatButton(
......
...@@ -293,7 +293,7 @@ class SimpleDialog extends StatelessWidget { ...@@ -293,7 +293,7 @@ class SimpleDialog extends StatelessWidget {
body.add(new Flexible( body.add(new Flexible(
child: new SingleChildScrollView( child: new SingleChildScrollView(
padding: contentPadding ?? const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), padding: contentPadding ?? const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
child: new BlockBody(children: children), child: new ListBody(children: children),
) )
)); ));
} }
......
...@@ -84,7 +84,7 @@ class ExpansionPanelList extends StatelessWidget { ...@@ -84,7 +84,7 @@ class ExpansionPanelList extends StatelessWidget {
} }
/// The children of the expansion panel list. They are layed in a similar /// The children of the expansion panel list. They are layed in a similar
/// fashion to [BlockBody]. /// fashion to [ListBody].
final List<ExpansionPanel> children; final List<ExpansionPanel> children;
/// The callback that gets called whenever one of the expand/collapse buttons /// The callback that gets called whenever one of the expand/collapse buttons
......
...@@ -74,7 +74,7 @@ class MaterialGap extends MergeableMaterialItem { ...@@ -74,7 +74,7 @@ class MaterialGap extends MergeableMaterialItem {
/// Displays a list of [MergeableMaterialItem] children. The list contains /// Displays a list of [MergeableMaterialItem] children. The list contains
/// [MaterialSlice] items whose boundaries are either "merged" with adjacent /// [MaterialSlice] items whose boundaries are either "merged" with adjacent
/// items or separated by a [MaterialGap]. The [children] are distributed along /// items or separated by a [MaterialGap]. The [children] are distributed along
/// the given [mainAxis] in the same way as the children of a [BlockBody]. When /// the given [mainAxis] in the same way as the children of a [ListBody]. When
/// the list of children changes, gaps are automatically animated open or closed /// the list of children changes, gaps are automatically animated open or closed
/// as needed. /// as needed.
/// ///
...@@ -522,7 +522,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid ...@@ -522,7 +522,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
borderRadius: _borderRadius(i - 1, widgets.isEmpty, false), borderRadius: _borderRadius(i - 1, widgets.isEmpty, false),
shape: BoxShape.rectangle shape: BoxShape.rectangle
), ),
child: new BlockBody( child: new ListBody(
mainAxis: config.mainAxis, mainAxis: config.mainAxis,
children: slices children: slices
) )
...@@ -593,7 +593,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid ...@@ -593,7 +593,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
borderRadius: _borderRadius(i - 1, widgets.isEmpty, true), borderRadius: _borderRadius(i - 1, widgets.isEmpty, true),
shape: BoxShape.rectangle shape: BoxShape.rectangle
), ),
child: new BlockBody( child: new ListBody(
mainAxis: config.mainAxis, mainAxis: config.mainAxis,
children: slices children: slices
) )
...@@ -602,7 +602,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid ...@@ -602,7 +602,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
slices = <Widget>[]; slices = <Widget>[];
} }
return new _MergeableMaterialBlockBody( return new _MergeableMaterialListBody(
mainAxis: config.mainAxis, mainAxis: config.mainAxis,
boxShadows: kElevationToShadow[config.elevation], boxShadows: kElevationToShadow[config.elevation],
items: _children, items: _children,
...@@ -635,8 +635,8 @@ class _MergeableMaterialSliceKey extends GlobalKey { ...@@ -635,8 +635,8 @@ class _MergeableMaterialSliceKey extends GlobalKey {
} }
} }
class _MergeableMaterialBlockBody extends BlockBody { class _MergeableMaterialListBody extends ListBody {
_MergeableMaterialBlockBody({ _MergeableMaterialListBody({
List<Widget> children, List<Widget> children,
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
this.items, this.items,
...@@ -647,24 +647,24 @@ class _MergeableMaterialBlockBody extends BlockBody { ...@@ -647,24 +647,24 @@ class _MergeableMaterialBlockBody extends BlockBody {
List<BoxShadow> boxShadows; List<BoxShadow> boxShadows;
@override @override
RenderBlock createRenderObject(BuildContext context) { RenderListBody createRenderObject(BuildContext context) {
return new _MergeableMaterialRenderBlock( return new _RenderMergeableMaterialListBody(
mainAxis: mainAxis, mainAxis: mainAxis,
boxShadows: boxShadows boxShadows: boxShadows
); );
} }
@override @override
void updateRenderObject(BuildContext context, RenderBlock renderObject) { void updateRenderObject(BuildContext context, RenderListBody renderObject) {
final _MergeableMaterialRenderBlock materialRenderBlock = renderObject; final _RenderMergeableMaterialListBody materialRenderListBody = renderObject;
materialRenderBlock materialRenderListBody
..mainAxis = mainAxis ..mainAxis = mainAxis
..boxShadows = boxShadows; ..boxShadows = boxShadows;
} }
} }
class _MergeableMaterialRenderBlock extends RenderBlock { class _RenderMergeableMaterialListBody extends RenderListBody {
_MergeableMaterialRenderBlock({ _RenderMergeableMaterialListBody({
List<RenderBox> children, List<RenderBox> children,
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
this.boxShadows this.boxShadows
...@@ -692,7 +692,7 @@ class _MergeableMaterialRenderBlock extends RenderBlock { ...@@ -692,7 +692,7 @@ class _MergeableMaterialRenderBlock extends RenderBlock {
int i = 0; int i = 0;
while (child != null) { while (child != null) {
final BlockParentData childParentData = child.parentData; final ListBodyParentData childParentData = child.parentData;
final Rect rect = (childParentData.offset + offset) & child.size; final Rect rect = (childParentData.offset + offset) & child.size;
if (i % 2 == 0) if (i % 2 == 0)
_paintShadows(context.canvas, rect); _paintShadows(context.canvas, rect);
......
...@@ -300,7 +300,7 @@ class _PopupMenu<T> extends StatelessWidget { ...@@ -300,7 +300,7 @@ class _PopupMenu<T> extends StatelessWidget {
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: _kMenuVerticalPadding vertical: _kMenuVerticalPadding
), ),
child: new BlockBody(children: children), child: new ListBody(children: children),
) )
) )
); );
......
...@@ -7,37 +7,39 @@ import 'dart:math' as math; ...@@ -7,37 +7,39 @@ import 'dart:math' as math;
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
/// Parent data for use with [RenderBlockBase]. /// Parent data for use with [RenderListBody].
class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { } class ListBodyParentData extends ContainerBoxParentDataMixin<RenderBox> { }
typedef double _ChildSizingFunction(RenderBox child); typedef double _ChildSizingFunction(RenderBox child);
/// Implements the block layout algorithm. /// Displays its children sequentially along a given axis, forcing them to the
/// dimensions of the parent in the other axis.
/// ///
/// In block layout, children are arranged linearly along the main axis (either /// This layout algorithm arranges its children linearly along the main axis
/// horizontally or vertically). In the cross axis, children are stretched to /// (either horizontally or vertically). In the cross axis, children are
/// match the block's cross-axis extent. In the main axis, children are given /// stretched to match the box's cross-axis extent. In the main axis, children
/// unlimited space and the block expands its main axis to contain all its /// are given unlimited space and the box expands its main axis to contain all
/// children. Because blocks expand in the main axis, blocks must be given /// its children. Because [RenderListBody] boxes expand in the main axis, they
/// unlimited space in the main axis, typically by being contained in a /// must be given unlimited space in the main axis, typically by being contained
/// viewport with a scrolling direction that matches the block's main axis. /// in a viewport with a scrolling direction that matches the box's main axis.
class RenderBlock extends RenderBox class RenderListBody extends RenderBox
with ContainerRenderObjectMixin<RenderBox, BlockParentData>, with ContainerRenderObjectMixin<RenderBox, ListBodyParentData>,
RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData> { RenderBoxContainerDefaultsMixin<RenderBox, ListBodyParentData> {
/// Creates a block render object. /// Creates a render object that arranges its children sequentially along a
/// given axis.
/// ///
/// By default, the block positions children along the vertical axis. /// By default, children are arranged along the vertical axis.
RenderBlock({ RenderListBody({
List<RenderBox> children, List<RenderBox> children,
Axis mainAxis: Axis.vertical Axis mainAxis: Axis.vertical,
}) : _mainAxis = mainAxis { }) : _mainAxis = mainAxis {
addAll(children); addAll(children);
} }
@override @override
void setupParentData(RenderBox child) { void setupParentData(RenderBox child) {
if (child.parentData is! BlockParentData) if (child.parentData is! ListBodyParentData)
child.parentData = new BlockParentData(); child.parentData = new ListBodyParentData();
} }
/// The direction to use as the main axis. /// The direction to use as the main axis.
...@@ -90,10 +92,10 @@ class RenderBlock extends RenderBox ...@@ -90,10 +92,10 @@ class RenderBlock extends RenderBox
break; break;
} }
throw new FlutterError( throw new FlutterError(
'RenderBlock must have unlimited space along its main axis.\n' 'RenderListBody must have unlimited space along its main axis.\n'
'RenderBlock does not clip or resize its children, so it must be ' 'RenderListBody does not clip or resize its children, so it must be '
'placed in a parent that does not constrain the block\'s main ' 'placed in a parent that does not constrain the main '
'axis. You probably want to put the RenderBlock inside a ' 'axis. You probably want to put the RenderListBody inside a '
'RenderViewport with a matching main axis.' 'RenderViewport with a matching main axis.'
); );
}); });
...@@ -112,11 +114,11 @@ class RenderBlock extends RenderBox ...@@ -112,11 +114,11 @@ class RenderBlock extends RenderBox
// more specific to the exact situation in that case, and don't mention // more specific to the exact situation in that case, and don't mention
// nesting blocks in the negative case. // nesting blocks in the negative case.
throw new FlutterError( throw new FlutterError(
'RenderBlock must have a bounded constraint for its cross axis.\n' 'RenderListBody must have a bounded constraint for its cross axis.\n'
'RenderBlock forces its children to expand to fit the block\'s container, ' 'RenderListBody forces its children to expand to fit the RenderListBody\'s container, '
'so it must be placed in a parent that does constrain the block\'s cross ' 'so it must be placed in a parent that constrains the cross '
'axis to a finite dimension. If you are attempting to nest a block with ' 'axis to a finite dimension. If you are attempting to nest a RenderListBody with '
'one direction inside a block of another direction, you will want to ' 'one direction inside one of another direction, you will want to '
'wrap the inner one inside a box that fixes the dimension in that direction, ' 'wrap the inner one inside a box that fixes the dimension in that direction, '
'for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. ' 'for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. '
'This is relatively expensive, however.' // (that's why we don't do it automatically) 'This is relatively expensive, however.' // (that's why we don't do it automatically)
...@@ -127,7 +129,7 @@ class RenderBlock extends RenderBox ...@@ -127,7 +129,7 @@ class RenderBlock extends RenderBox
RenderBox child = firstChild; RenderBox child = firstChild;
while (child != null) { while (child != null) {
child.layout(innerConstraints, parentUsesSize: true); child.layout(innerConstraints, parentUsesSize: true);
final BlockParentData childParentData = child.parentData; final ListBodyParentData childParentData = child.parentData;
switch (mainAxis) { switch (mainAxis) {
case Axis.horizontal: case Axis.horizontal:
childParentData.offset = new Offset(position, 0.0); childParentData.offset = new Offset(position, 0.0);
...@@ -164,7 +166,7 @@ class RenderBlock extends RenderBox ...@@ -164,7 +166,7 @@ class RenderBlock extends RenderBox
RenderBox child = firstChild; RenderBox child = firstChild;
while (child != null) { while (child != null) {
extent = math.max(extent, childSize(child)); extent = math.max(extent, childSize(child));
final BlockParentData childParentData = child.parentData; final ListBodyParentData childParentData = child.parentData;
child = childParentData.nextSibling; child = childParentData.nextSibling;
} }
return extent; return extent;
...@@ -175,7 +177,7 @@ class RenderBlock extends RenderBox ...@@ -175,7 +177,7 @@ class RenderBlock extends RenderBox
RenderBox child = firstChild; RenderBox child = firstChild;
while (child != null) { while (child != null) {
extent += childSize(child); extent += childSize(child);
final BlockParentData childParentData = child.parentData; final ListBodyParentData childParentData = child.parentData;
child = childParentData.nextSibling; child = childParentData.nextSibling;
} }
return extent; return extent;
......
...@@ -1539,19 +1539,30 @@ class SliverPadding extends SingleChildRenderObjectWidget { ...@@ -1539,19 +1539,30 @@ class SliverPadding extends SingleChildRenderObjectWidget {
// LAYOUT NODES // LAYOUT NODES
/// A widget that uses the block layout algorithm for its children. /// A widget that arranges its children sequentially along a given axis, forcing
/// them to the dimension of the parent in the other axis.
/// ///
/// This widget is rarely used directly. Instead, consider using [SliverList], /// This widget is rarely used directly. Instead, consider using [ListView],
/// which combines a similar layout algorithm with scrolling behavior, or /// which combines a similar layout algorithm with scrolling behavior, or
/// [Column], which gives you more flexible control over the layout of a /// [Column], which gives you more flexible control over the layout of a
/// vertical set of boxes. /// vertical set of boxes.
/// ///
/// For details about the block layout algorithm, see [RenderBlockBase]. /// See also:
class BlockBody extends MultiChildRenderObjectWidget { ///
/// Creates a block layout widget. /// * [RenderListBody], which implements this layout algorithm and the
/// documentation for which describes some of its subtleties.
/// * [SingleChildScrollView], which is sometimes used with [ListBody] to
/// make the contents scrollable.
/// * [Column] and [Row], which implement a more elaborate version of
/// this layout algorithm (at the cost of being slightly less efficient).
/// * [ListView], which implements an efficient scrolling version of this
/// layout algorithm.
class ListBody extends MultiChildRenderObjectWidget {
/// Creates a layout widget that arranges its children sequentially along a
/// given axis.
/// ///
/// By default, the [mainAxis] is [Axis.vertical]. /// By default, the [mainAxis] is [Axis.vertical].
BlockBody({ ListBody({
Key key, Key key,
this.mainAxis: Axis.vertical, this.mainAxis: Axis.vertical,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
...@@ -1562,10 +1573,10 @@ class BlockBody extends MultiChildRenderObjectWidget { ...@@ -1562,10 +1573,10 @@ class BlockBody extends MultiChildRenderObjectWidget {
final Axis mainAxis; final Axis mainAxis;
@override @override
RenderBlock createRenderObject(BuildContext context) => new RenderBlock(mainAxis: mainAxis); RenderListBody createRenderObject(BuildContext context) => new RenderListBody(mainAxis: mainAxis);
@override @override
void updateRenderObject(BuildContext context, RenderBlock renderObject) { void updateRenderObject(BuildContext context, RenderListBody renderObject) {
renderObject.mainAxis = mainAxis; renderObject.mainAxis = mainAxis;
} }
} }
......
...@@ -23,12 +23,12 @@ import 'scrollable.dart'; ...@@ -23,12 +23,12 @@ import 'scrollable.dart';
/// It is also useful if you need to shrink-wrap in both axes (the main /// It is also useful if you need to shrink-wrap in both axes (the main
/// scrolling direction as well as the cross axis), as one might see in a dialog /// scrolling direction as well as the cross axis), as one might see in a dialog
/// or pop-up menu. In that case, you might pair the [SingleChildScrollView] /// or pop-up menu. In that case, you might pair the [SingleChildScrollView]
/// with a [BlockBody] child. /// with a [ListBody] child.
/// ///
/// When you have a list of children and do not require cross-axis /// When you have a list of children and do not require cross-axis
/// shrink-wrapping behavior, for example a scrolling list that is always the /// shrink-wrapping behavior, for example a scrolling list that is always the
/// width of the screen, consider [ListView], which is vastly more efficient /// width of the screen, consider [ListView], which is vastly more efficient
/// that a [SingleChildScrollView] containing a [BlockBody] or [Column] with /// that a [SingleChildScrollView] containing a [ListBody] or [Column] with
/// many children. /// many children.
/// ///
/// See also: /// See also:
......
...@@ -6,14 +6,14 @@ import 'package:flutter/rendering.dart'; ...@@ -6,14 +6,14 @@ import 'package:flutter/rendering.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
test('block and paragraph intrinsics', () { test('list body and paragraph intrinsics', () {
final RenderParagraph paragraph = new RenderParagraph( final RenderParagraph paragraph = new RenderParagraph(
const TextSpan( const TextSpan(
style: const TextStyle(height: 1.0), style: const TextStyle(height: 1.0),
text: 'Hello World' text: 'Hello World'
) )
); );
final RenderBlock testBlock = new RenderBlock( final RenderListBody testBlock = new RenderListBody(
children: <RenderBox>[ children: <RenderBox>[
paragraph, paragraph,
] ]
......
...@@ -18,7 +18,7 @@ Widget buildSingleChildScrollView(Axis scrollDirection, { bool reverse: false }) ...@@ -18,7 +18,7 @@ Widget buildSingleChildScrollView(Axis scrollDirection, { bool reverse: false })
child: new SingleChildScrollView( child: new SingleChildScrollView(
scrollDirection: scrollDirection, scrollDirection: scrollDirection,
reverse: reverse, reverse: reverse,
child: new BlockBody( child: new ListBody(
mainAxis: scrollDirection, mainAxis: scrollDirection,
children: <Widget>[ children: <Widget>[
new Container(key: const ValueKey<int>(0), width: 200.0, height: 200.0), new Container(key: const ValueKey<int>(0), width: 200.0, height: 200.0),
...@@ -178,7 +178,7 @@ void main() { ...@@ -178,7 +178,7 @@ void main() {
width: 600.0, width: 600.0,
height: 400.0, height: 400.0,
child: new SingleChildScrollView( child: new SingleChildScrollView(
child: new BlockBody( child: new ListBody(
children: <Widget>[ children: <Widget>[
new Container(height: 200.0), new Container(height: 200.0),
new Container(height: 200.0), new Container(height: 200.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