pub struct AspectRatio {
pub key: Option<KeyRef>,
pub aspect_ratio: f64,
pub child: Option<WidgetRef>,
}Expand description
A widget that attempts to size the child to a specific aspect ratio.
The widget first tries the largest width permitted by the layout constraints. The height of the widget is determined by applying the given aspect ratio to the width, expressed as a ratio of width to height.
For example, a 16:9 width:height aspect ratio would have a value of 16.0/9.0. If the maximum width is infinite, the initial width is determined by applying the aspect ratio to the maximum height.
Now consider a second example, this time with an aspect ratio of 2.0 and layout constraints that require the width to be between 0.0 and 100.0 and the height to be between 0.0 and 100.0. We’ll select a width of 100.0 (the biggest allowed) and a height of 50.0 (to match the aspect ratio).
§Setting the aspect ratio in unconstrained situations
When using a widget such as FittedBox, the constraints are unbounded. This
results in AspectRatio being unable to find a suitable set of constraints
to apply. In that situation, consider explicitly setting a size using
SizedBox instead of setting the aspect ratio using AspectRatio. The size
is then scaled appropriately by the FittedBox.
See also:
Align, a widget that aligns its child within itself and optionally sizes itself based on the child’s size.ConstrainedBox, a widget that imposes additional constraints on its child.UnconstrainedBox, a container that tries to let its child draw without constraints.- The catalog of layout widgets.
Fields§
§key: Option<KeyRef>§aspect_ratio: f64The aspect ratio to attempt to use.
The aspect ratio is expressed as a ratio of width to height. For example, a 16:9 width:height aspect ratio would have a value of 16.0/9.0.
child: Option<WidgetRef>Implementations§
Source§impl AspectRatio
impl AspectRatio
Sourcepub fn new(aspect_ratio: f64) -> AspectRatio
pub fn new(aspect_ratio: f64) -> AspectRatio
Creates a widget with a specific aspect ratio; Dart’s optional named arguments are the setters.
The aspect_ratio argument must be a finite number greater than zero.
Sourcepub fn key(self, key: KeyRef) -> AspectRatio
pub fn key(self, key: KeyRef) -> AspectRatio
Dart AspectRatio(key:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> AspectRatio
pub fn child<K>(self, child: impl IntoWidget<K>) -> AspectRatio
Dart AspectRatio(child:).
Trait Implementations§
Source§impl Debug for AspectRatio
impl Debug for AspectRatio
Source§impl RenderObjectWidget for AspectRatio
impl RenderObjectWidget for AspectRatio
Source§type RenderObject = RenderAspectRatio
type RenderObject = RenderAspectRatio
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<RenderAspectRatio>,
)
fn update_render_object( &self, app: &mut App, _context: BuildContext, render_object: RenderHandle<RenderAspectRatio>, )
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 AspectRatio
impl !Send for AspectRatio
impl !Sync for AspectRatio
impl !UnwindSafe for AspectRatio
impl Forget for AspectRatio
impl Freeze for AspectRatio
impl Move for AspectRatio
impl Unpin for AspectRatio
impl UnsafeUnpin for AspectRatiowhere
*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.