position method
Sets the position type for this widget to control positioning context.
Determines whether this widget establishes a positioning context for its absolutely positioned children (when used with AbsoluteItem).
-
PositionType.none (default): Does not establish a positioning context. Absolutely positioned children will skip this element and position themselves relative to the nearest ancestor with PositionType.relative.
-
PositionType.relative: Establishes a positioning context. Absolutely positioned children will position themselves relative to this element's edges.
This is similar to CSS positioning where position: static doesn't create a
containing block, while position: relative does.
The optional key parameter assigns a key to the wrapped widget.
Example:
// Create a positioning context for absolutely positioned children
Container()
.position(PositionType.relative)
.width(200.size)
.height(200.size),
Implementation
Widget position(PositionType position, [Key? key]) {
return _WidgetWrapper._wrapOrCopyWith(
child: this,
key: key != null ? () => key : null,
position: () => position,
);
}