pub struct Padding {
pub key: Option<KeyRef>,
pub padding: EdgeInsetsGeometry,
pub child: Option<WidgetRef>,
}Expand description
A widget that insets its child by the given padding.
When passing layout constraints to its child, padding shrinks the constraints by the given padding, causing the child to layout at a smaller size. Padding then sizes itself to its child’s size, inflated by the padding, effectively creating empty space around the child.
This snippet creates “Hello World!” Text inside a Card that is indented
by sixteen pixels in each direction.
Card {
child: Padding {
padding: EdgeInsetsGeometry::all(16.0),
child: Some(Text("Hello World!")),
..Default::default()
},
}§Design discussion
§Why use a Padding widget rather than a Container with Container.padding?
There isn’t really any difference between the two. If you supply a
Container.padding argument, Container builds a Padding widget
for you.
Container doesn’t implement its properties directly. Instead, Container
combines a number of simpler widgets together into a convenient package. For
example, the Container.padding property causes the container to build a
Padding widget and the Container.decoration property causes the
container to build a DecoratedBox widget. If you find Container
convenient, feel free to use it. If not, feel free to build these simpler
widgets in whatever combination meets your needs.
In fact, the majority of widgets in Flutter are combinations of other simpler widgets. Composition, rather than inheritance, is the primary mechanism for building up widgets.
See also:
EdgeInsets, the class that is used to describe the padding dimensions.AnimatedPadding, which animates changes inpaddingover a given duration.SliverPadding, the sliver equivalent of this widget.- The catalog of layout widgets.
Fields§
§key: Option<KeyRef>§padding: EdgeInsetsGeometryThe amount of space by which to inset the child.
child: Option<WidgetRef>Implementations§
Trait Implementations§
Source§impl RenderObjectWidget for Padding
impl RenderObjectWidget for Padding
Source§type RenderObject = RenderPadding
type RenderObject = RenderPadding
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<RenderPadding>,
)
fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderPadding>, )
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 Padding
impl !Send for Padding
impl !Sync for Padding
impl !UnwindSafe for Padding
impl Forget for Padding
impl Freeze for Padding
impl Move for Padding
impl Unpin for Padding
impl UnsafeUnpin for Paddingwhere
*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.