xPositioned method
A widget that controls where a child of a Stack
is positioned.
A Positioned
widget must be a descendant of a Stack
, and the path from
the Positioned
widget to its enclosing Stack
must contain only
StatelessWidget
s or StatefulWidget
s (not other kinds of widgets, like
RenderObjectWidget
s).
If a widget is wrapped in a Positioned
, then it is a positioned widget
in its Stack
. If the top
property is non-null, the top edge of this child
will be positioned top
layout units from the top of the stack widget. The
right
, bottom
, and left
properties work analogously.
If both the top
and bottom
properties are non-null, then the child will
be forced to have exactly the height required to satisfy both constraints.
Similarly, setting the right
and left
properties to non-null values will
force the child to have a particular width. Alternatively the width
and
height
properties can be used to give the dimensions, with one
corresponding position property (e.g. top
and height
).
If all three values on a particular axis are null, then the
Stack.alignment
property is used to position the child.
If all six values are null, the child is a non-positioned child. The Stack
uses only the non-positioned children to size itself.
See also:
AnimatedPositioned
, which automatically transitions the child's position over a given duration whenever the given position changes.PositionedTransition
, which takes a providedAnimation
to transition changes in the child's position over a given duration.PositionedDirectional
, which adapts to the ambientDirectionality
.
Implementation
Widget xPositioned({
/// The distance that the child's left edge is inset from the left of the stack.
///
/// Only two out of the three horizontal values ([left], [right], [width]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// horizontally.
final double left,
/// The distance that the child's top edge is inset from the top of the stack.
///
/// Only two out of the three vertical values ([top], [bottom], [height]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// vertically.
final double top,
/// The distance that the child's right edge is inset from the right of the stack.
///
/// Only two out of the three horizontal values ([left], [right], [width]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// horizontally.
final double right,
/// The distance that the child's bottom edge is inset from the bottom of the stack.
///
/// Only two out of the three vertical values ([top], [bottom], [height]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// vertically.
final double bottom,
/// The child's width.
///
/// Only two out of the three horizontal values ([left], [right], [width]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// horizontally.
final double width,
/// The child's height.
///
/// Only two out of the three vertical values ([top], [bottom], [height]) can be
/// set. The third must be null.
///
/// If all three are null, the [Stack.alignment] is used to position the child
/// vertically.
final double height,
final Key key,
}) {
return Positioned(
bottom: bottom,
height: height,
key: key,
left: left,
right: right,
top: top,
width: width,
child: this,
);
}