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

Tweaks to the Flex documentation. (#6547)

parent 7acc9965
...@@ -1879,15 +1879,30 @@ class GridPlacementData<DataType> extends ParentDataWidget<GridRenderObjectWidge ...@@ -1879,15 +1879,30 @@ class GridPlacementData<DataType> extends ParentDataWidget<GridRenderObjectWidge
/// ///
/// For details about the flex layout algorithm, see [RenderFlex]. To control /// For details about the flex layout algorithm, see [RenderFlex]. To control
/// the flex of child widgets, see the [Flexible] widget. /// the flex of child widgets, see the [Flexible] widget.
///
/// The Flex widget allows you to control the axis along which the children
/// are placed (horizontal or vertical). If you know the axis in advance, then
/// consider using a [Row] (if it's horizontal) or [Column] (if it's vertical)
/// instead, since that will be less verbose.
///
/// The Flex widget does not scroll (and in general it is considered an error to
/// have more children in a Flex than will fit in the available room). If you
/// have some widgets and want them to be able to scroll if there is
/// insufficient room, consider using a [Block].
///
/// If you only have one child, then rather than using [Flex], [Row], or
/// [Column], consider using [Align] or [Center] to position the child.
class Flex extends MultiChildRenderObjectWidget { class Flex extends MultiChildRenderObjectWidget {
/// Creates a flex layout. /// Creates a flex layout.
/// ///
/// The [direction] is required.
///
/// The [direction], [mainAxisAlignment], and [crossAxisAlignment] arguments /// The [direction], [mainAxisAlignment], and [crossAxisAlignment] arguments
/// must not be null. If [crossAxisAlignment] is /// must not be null. If [crossAxisAlignment] is
/// [CrossAxisAlignment.baseline], then [textBaseline] must not be null. /// [CrossAxisAlignment.baseline], then [textBaseline] must not be null.
Flex({ Flex({
Key key, Key key,
this.direction: Axis.horizontal, @required this.direction,
this.mainAxisAlignment: MainAxisAlignment.start, this.mainAxisAlignment: MainAxisAlignment.start,
this.mainAxisSize: MainAxisSize.max, this.mainAxisSize: MainAxisSize.max,
this.crossAxisAlignment: CrossAxisAlignment.center, this.crossAxisAlignment: CrossAxisAlignment.center,
...@@ -1902,6 +1917,11 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -1902,6 +1917,11 @@ class Flex extends MultiChildRenderObjectWidget {
} }
/// The direction to use as the main axis. /// The direction to use as the main axis.
///
/// If you know the axis in advance, then consider using a [Row] (if it's
/// horizontal) or [Column] (if it's vertical) instead of a [Flex], since that
/// will be less verbose. (For [Row] and [Column] this property is fixed to
/// the appropriate axis.)
final Axis direction; final Axis direction;
/// How the children should be placed along the main axis. /// How the children should be placed along the main axis.
...@@ -1958,6 +1978,9 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -1958,6 +1978,9 @@ class Flex extends MultiChildRenderObjectWidget {
/// insufficient room, consider using a [Block]. /// insufficient room, consider using a [Block].
/// ///
/// For a vertical variant, see [Column]. /// For a vertical variant, see [Column].
///
/// If you only have one child, then consider using [Align] or [Center] to
/// position the child.
class Row extends Flex { class Row extends Flex {
/// Creates a horizontal array of children. /// Creates a horizontal array of children.
/// ///
...@@ -1993,6 +2016,9 @@ class Row extends Flex { ...@@ -1993,6 +2016,9 @@ class Row extends Flex {
/// insufficient room, consider using a [Block]. /// insufficient room, consider using a [Block].
/// ///
/// For a horizontal variant, see [Row]. /// For a horizontal variant, see [Row].
///
/// If you only have one child, then consider using [Align] or [Center] to
/// position the child.
class Column extends Flex { class Column extends Flex {
/// Creates a vertical array of children. /// Creates a vertical array of children.
/// ///
...@@ -2017,14 +2043,15 @@ class Column extends Flex { ...@@ -2017,14 +2043,15 @@ class Column extends Flex {
); );
} }
/// A widget that controls how a child of a [Flex], [Row], or [Column] flexes. /// A widget that controls how a child of a [Row], [Column], or [Flex] flexes.
/// ///
/// A [Flexible] widget must be a descendant of a [Flex], [Row], or [Column], /// A [Flexible] widget must be a descendant of a [Row], [Column], or [Flex],
/// and the path from the [Flexible] widget to its enclosing [Flex], [Row], or /// and the path from the [Flexible] widget to its enclosing [Row], [Column], or
/// [Column] must contain only [StatelessWidget]s or [StatefulWidget]s (not /// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other
/// other kinds of widgets, like [RenderObjectWidget]s). /// kinds of widgets, like [RenderObjectWidget]s).
class Flexible extends ParentDataWidget<Flex> { class Flexible extends ParentDataWidget<Flex> {
/// Creates a widget that controls how a child of a [Flex], [Row], or [Column] flexes. /// Creates a widget that controls how a child of a [Row], [Column], or [Flex]
/// flexes.
Flexible({ Flexible({
Key key, Key key,
this.flex: 1, this.flex: 1,
......
...@@ -265,7 +265,7 @@ void main() { ...@@ -265,7 +265,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new Container( new Container(
child: new Flex( child: new Row(
children: <Widget>[ children: <Widget>[
new Positioned( new Positioned(
top: 6.0, top: 6.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