pub struct Flex {
pub key: Option<KeyRef>,
pub direction: Axis,
pub main_axis_alignment: MainAxisAlignment,
pub main_axis_size: MainAxisSize,
pub cross_axis_alignment: CrossAxisAlignment,
pub text_direction: Option<TextDirection>,
pub vertical_direction: VerticalDirection,
pub text_baseline: Option<TextBaseline>,
pub clip_behavior: Clip,
pub spacing: f64,
pub children: Vec<WidgetRef>,
}Expand description
A widget that displays its children in a one-dimensional array.
The Flex widget allows you to control the axis along which the children are placed
(horizontal or vertical). This is referred to as the main axis. If you know the main axis
in advance, then consider using a Row (if it’s horizontal) or Column (if it’s
vertical) instead, because that will be less verbose.
To cause a child to expand to fill the available space in the direction
of this widget’s main axis, wrap the child in an Expanded widget.
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 ListView.
If you only have one child, then rather than using Flex, Row or Column, consider
using Align or Center to position the child.
§Layout algorithm
This section describes how a Flex is rendered by the framework.
Layout for a Flex proceeds in six steps:
- Layout each child with a
Noneor zero flex factor with unbounded main axis constraints and the incoming cross axis constraints. If thecross_axis_alignmentisCrossAxisAlignment::Stretch, instead use tight cross axis constraints that match the incoming max extent in the cross axis. - Divide the remaining main axis space among the children with non-zero flex factors according to their flex factor.
- Layout each of the remaining children with the same cross axis constraints as in step 1, but instead of using unbounded main axis constraints, use max axis constraints based on the amount of space allocated in step 2.
- The width of the
Flexis determined by themain_axis_sizeproperty. - Determine the position for each child according to the
main_axis_alignmentand thecross_axis_alignment.
See also:
Row, for a version of this widget that is always horizontal.Column, for a version of this widget that is always vertical.Expanded, to indicate children that should take all the remaining room.Flexible, to indicate children that should share the remaining room.Spacer, a widget that takes up space proportional to its flex value.
Fields§
§key: Option<KeyRef>§direction: AxisThe 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.
main_axis_alignment: MainAxisAlignmentHow the children should be placed along the main axis.
For example, MainAxisAlignment::Start, the default, places the children at the start
(i.e., the left for a Row or the top for a Column) of the main axis.
main_axis_size: MainAxisSizeHow much space should be occupied in the main axis.
After allocating space to children, there might be some remaining free space. This value controls whether to maximize or minimize the amount of free space, subject to the incoming layout constraints.
cross_axis_alignment: CrossAxisAlignmentHow the children should be placed along the cross axis.
For example, CrossAxisAlignment::Center, the default, centers the children in the
cross axis (e.g., horizontally for a Column).
text_direction: Option<TextDirection>Determines the order to lay children out horizontally and how to interpret start and
end in the horizontal direction.
Defaults to the ambient Directionality.
If the direction is Axis::Horizontal, this controls the order in
which the children are positioned (left-to-right or right-to-left), and the meaning of
the main_axis_alignment property’s
MainAxisAlignment::Start and MainAxisAlignment::End values.
If the direction is Axis::Vertical, this controls the meaning of
the cross_axis_alignment property’s
CrossAxisAlignment::Start and CrossAxisAlignment::End values.
vertical_direction: VerticalDirectionDetermines the order to lay children out vertically and how to interpret start and
end in the vertical direction.
Defaults to VerticalDirection::Down.
text_baseline: Option<TextBaseline>If aligning items according to their baseline, which baseline to use.
This must be set if using baseline alignment. There is no default because there is no way for the framework to know the correct baseline a priori.
clip_behavior: ClipDefaults to Clip::None.
spacing: f64How much space to place between children in the main axis.
children: Vec<WidgetRef>Implementations§
Source§impl Flex
impl Flex
Sourcepub fn new(direction: Axis) -> Flex
pub fn new(direction: Axis) -> Flex
Creates a flex layout; Dart’s optional named arguments are the setters.
The direction is required.
The text_direction defaults to the ambient Directionality,
if any. If there is no ambient directionality, and a text direction is going to be
necessary to decide which direction to lay the children in or to disambiguate start or
end values for the main or cross axis directions, the
text_direction must not be None.
Sourcepub fn main_axis_alignment(self, main_axis_alignment: MainAxisAlignment) -> Flex
pub fn main_axis_alignment(self, main_axis_alignment: MainAxisAlignment) -> Flex
Dart Flex(mainAxisAlignment:).
Sourcepub fn main_axis_size(self, main_axis_size: MainAxisSize) -> Flex
pub fn main_axis_size(self, main_axis_size: MainAxisSize) -> Flex
Dart Flex(mainAxisSize:).
Sourcepub fn cross_axis_alignment(
self,
cross_axis_alignment: CrossAxisAlignment,
) -> Flex
pub fn cross_axis_alignment( self, cross_axis_alignment: CrossAxisAlignment, ) -> Flex
Dart Flex(crossAxisAlignment:).
Sourcepub fn text_direction(self, text_direction: TextDirection) -> Flex
pub fn text_direction(self, text_direction: TextDirection) -> Flex
Dart Flex(textDirection:).
Sourcepub fn vertical_direction(self, vertical_direction: VerticalDirection) -> Flex
pub fn vertical_direction(self, vertical_direction: VerticalDirection) -> Flex
Dart Flex(verticalDirection:).
Sourcepub fn text_baseline(self, text_baseline: TextBaseline) -> Flex
pub fn text_baseline(self, text_baseline: TextBaseline) -> Flex
Dart Flex(textBaseline:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Flex
pub fn clip_behavior(self, clip_behavior: Clip) -> Flex
Dart Flex(clipBehavior:).
Sourcepub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> Flex
pub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> Flex
Dart Flex(children:).
Sourcepub fn get_effective_text_direction(
&self,
app: &mut App,
context: BuildContext,
) -> Option<TextDirection>
pub fn get_effective_text_direction( &self, app: &mut App, context: BuildContext, ) -> Option<TextDirection>
The value to pass to RenderFlex::set_text_direction.
This value is derived from the text_direction property and the
ambient Directionality. The value is None if there is no need to specify the text
direction. In practice there’s always a need to specify the direction except for
vertical flexes (e.g. Columns) whose
cross_axis_alignment is not dependent on the text
direction (not start or end). In particular, a Row always needs a text direction
because the text direction controls its layout order. (For Columns, the layout order
is controlled by vertical_direction, which is always
specified as it does not depend on an inherited widget and defaults to
VerticalDirection::Down.)
Trait Implementations§
Source§impl MultiChildRenderObjectWidget for Flex
impl MultiChildRenderObjectWidget for Flex
Source§impl RenderObjectWidget for Flex
impl RenderObjectWidget for Flex
Source§type RenderObject = RenderFlex
type RenderObject = RenderFlex
covariant RenderObject parameter type.Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_render_object(
&self,
app: &mut App,
context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
context: BuildContext,
render_object: RenderHandle<RenderFlex>,
)
fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderFlex>, )
create_render_object. Read moreSource§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Source§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<Self::RenderObject>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Auto Trait Implementations§
impl !RefUnwindSafe for Flex
impl !Send for Flex
impl !Sync for Flex
impl !UnwindSafe for Flex
impl Forget for Flex
impl Freeze for Flex
impl Move for Flex
impl Unpin for Flex
impl UnsafeUnpin for Flexwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Rc<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.