pub struct SizedBox {
pub key: Option<KeyRef>,
pub width: Option<f64>,
pub height: Option<f64>,
pub child: Option<WidgetRef>,
}Expand description
A box with a specified size.
If given a child, this widget forces it to have a specific width and/or height.
These values will be ignored if this widget’s parent does not permit them.
For example, this happens if the parent is the screen (forces the child to
be the same size as the parent), or another SizedBox (forces its child to
have a specific width and/or height). This can be remedied by wrapping the
child SizedBox in a widget that does permit it to be any size up to the
size of the parent, such as Center or Align.
If either the width or height is None, this widget will try to size itself to
match the child’s size in that dimension. If the child’s size depends on the
size of its parent, the height and width must be provided.
If not given a child, SizedBox will try to size itself as close to the
specified height and width as possible given the parent’s constraints. If
height or width is None or unspecified, it will be treated as zero.
The expand constructor can be used to make a SizedBox that sizes
itself to fit the parent. It is equivalent to setting width and height to
f64::INFINITY.
This snippet makes the child widget (a Card with some Text) have the
exact size 200x300, parental constraints permitting:
SizedBox {
width: Some(200.0),
height: Some(300.0),
child: Some(Card(child: Text("Hello World!"))),
..Default::default()
}See also:
ConstrainedBox, a more generic version of this class that takes arbitraryBoxConstraintsinstead of an explicit width and height.UnconstrainedBox, a container that tries to let its child draw without constraints.FractionallySizedBox, a widget that sizes its child to a fraction of the total available space.AspectRatio, a widget that attempts to fit within the parent’s constraints while also sizing its child to match a given aspect ratio.FittedBox, which sizes and positions its child widget to fit the parent according to a givenBoxFitdiscipline.- The catalog of layout widgets.
Dart’s named constructors are the associated functions expand,
shrink, from_size, and square;
set a key through struct update syntax: SizedBox { key: Some(key), ..SizedBox::expand(child) }.
Fields§
§key: Option<KeyRef>§width: Option<f64>If non-None, requires the child to have exactly this width.
height: Option<f64>If non-None, requires the child to have exactly this height.
child: Option<WidgetRef>Implementations§
Trait Implementations§
Source§impl RenderObjectWidget for SizedBox
impl RenderObjectWidget for SizedBox
Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Dart’s SizedBox.toStringShort: SizedBox.expand and SizedBox.shrink by the sizes
those constructors give.
Source§type RenderObject = RenderConstrainedBox
type RenderObject = RenderConstrainedBox
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<RenderConstrainedBox>,
)
fn update_render_object( &self, app: &mut App, _context: BuildContext, render_object: RenderHandle<RenderConstrainedBox>, )
create_render_object. Read moreSource§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 SizedBox
impl !Send for SizedBox
impl !Sync for SizedBox
impl !UnwindSafe for SizedBox
impl Forget for SizedBox
impl Freeze for SizedBox
impl Move for SizedBox
impl Unpin for SizedBox
impl UnsafeUnpin for SizedBoxwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<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<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.