pub struct Card {
pub key: Option<KeyRef>,
pub color: Option<Color>,
pub shadow_color: Option<Color>,
pub surface_tint_color: Option<Color>,
pub elevation: Option<f64>,
pub shape: Option<ShapeBorderRef>,
pub border_on_foreground: bool,
pub clip_behavior: Option<Clip>,
pub margin: Option<EdgeInsetsGeometry>,
pub semantic_container: bool,
pub child: Option<WidgetRef>,
/* private fields */
}Expand description
A Material Design card: a panel with slightly rounded corners and an elevation shadow.
A card is a sheet of Material used to represent some related information,
for example an album, a geographical location, a meal, contact details, etc.
Sometimes the primary action area of a card is the card itself. Cards can be one large touch target that shows a detail screen when tapped.
For Material Design 2 (when ThemeData::use_material3 is false), there is a
single card type: the elevated card. In that mode the named constructors
(Card::filled, Card::outlined) behave the same as the default Card::new.
For Material Design 3 (when ThemeData::use_material3 is true), three visual
variants are available: the default Card::new (elevated), Card::filled, and
Card::outlined. All variants share the same theme class, CardThemeData,
so theme properties (for example CardThemeData::shape) apply to every card
variant within the theme’s scope.
See also:
ListTile, to display icons and text in a card.ShowDialog, to display a modal card.- https://material.io/design/components/cards.html
- https://m3.material.io/components/cards
Fields§
§key: Option<KeyRef>§color: Option<Color>The card’s background color.
Defines the card’s Material::color.
If this property is null then the ambient CardTheme::color is used. If that is null,
and ThemeData::use_material3 is true, then ColorScheme::surface_container_low of
ThemeData::color_scheme is used. Otherwise, ThemeData::card_color is used.
shadow_color: Option<Color>The color to paint the shadow below the card.
If null then the ambient CardThemeData::shadow_color is used.
If that’s null too, then the overall theme’s ThemeData::shadow_color
(default black) is used.
surface_tint_color: Option<Color>The color used as an overlay on color to indicate elevation.
This is not recommended for use. Material 3 spec
introduced a set of tone-based surfaces and surface containers in its ColorScheme,
which provide more flexibility. The intention is to eventually remove surface tint color
from the framework.
If this is null, no overlay will be applied. Otherwise this color
will be composited on top of color with an opacity related
to elevation and used to paint the background of the card.
The default is Colors::TRANSPARENT.
See Material::surface_tint_color for more details on how this
overlay is applied.
elevation: Option<f64>The z-coordinate at which to place this card. This controls the size of the shadow below the card.
Defines the card’s Material::elevation.
If this property is null then the ambient CardThemeData::elevation is
used. If that’s null, the default value is 1.0.
shape: Option<ShapeBorderRef>The shape of the card’s Material.
Defines the card’s Material::shape.
If null, the ambient CardTheme::shape from ThemeData::card_theme is used.
If that is also null, the shape defaults to a RoundedRectangleBorder.
The default corner radius is 12.0 when ThemeData::use_material3 is true,
and 4.0 otherwise. For Material 3 outlined cards, the default shape
also includes a border side (see OutlinedBorder::side).
border_on_foreground: boolWhether to paint the shape border in front of the
child.
The default value is true.
If false, the border will be painted behind the child.
clip_behavior: Option<Clip>The content will be clipped (or not) according to this option.
If this property is null then the ambient CardThemeData::clip_behavior is
used. If that’s null then the behavior will be Clip::None.
margin: Option<EdgeInsetsGeometry>The empty space that surrounds the card.
Defines the card’s outer Container::margin.
If this property is null then the ambient CardThemeData::margin is used.
If that’s null, the default margin is 4.0 logical pixels on
all sides: EdgeInsets::all(4.0).
semantic_container: boolWhether this widget represents a single semantic container, or if false a collection of individual semantic nodes.
Defaults to true.
Setting this flag to true will attempt to merge all child semantics into this node. Setting this flag to false will force all child semantic nodes to be explicit.
This flag should be false if the card contains multiple different types of content.
child: Option<WidgetRef>The widget below this widget in the tree.
Implementations§
Source§impl Card
impl Card
Sourcepub fn new() -> Card
pub fn new() -> Card
Creates an elevated variant of Card.
Elevated cards have a drop shadow, providing more separation from the background than filled cards, but less than outlined cards.
The elevation must be null or non-negative.
Sourcepub fn filled() -> Card
pub fn filled() -> Card
Create a filled variant of Card.
Filled cards provide subtle separation from the background. This has less emphasis than elevated cards (the default) or outlined cards.
If ThemeData::use_material3 is false, this constructor is equivalent to
Card::new.
Sourcepub fn outlined() -> Card
pub fn outlined() -> Card
Create an outlined variant of Card.
Outlined cards have a visual boundary around the container. This can provide greater emphasis than the other types.
The card’s outline is defined by the shape property. By default, the
card uses a RoundedRectangleBorder with a 12.0 corner radius, a 1.0
border width, and the color from ColorScheme::outline_variant. If you
provide a custom shape, it is recommended to use an OutlinedBorder
with a non-null OutlinedBorder::side to keep a visible outline.
If ThemeData::use_material3 is false, this constructor is equivalent to
Card::new.
Sourcepub fn shadow_color(self, shadow_color: Color) -> Card
pub fn shadow_color(self, shadow_color: Color) -> Card
Dart Card(shadowColor:).
Sourcepub fn surface_tint_color(self, surface_tint_color: Color) -> Card
pub fn surface_tint_color(self, surface_tint_color: Color) -> Card
Dart Card(surfaceTintColor:).
Sourcepub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Card
pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Card
Dart Card(shape:).
Sourcepub fn border_on_foreground(self, border_on_foreground: bool) -> Card
pub fn border_on_foreground(self, border_on_foreground: bool) -> Card
Dart Card(borderOnForeground:).
Sourcepub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> Card
pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> Card
Dart Card(margin:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Card
pub fn clip_behavior(self, clip_behavior: Clip) -> Card
Dart Card(clipBehavior:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> Card
pub fn child<K>(self, child: impl IntoWidget<K>) -> Card
Dart Card(child:).
Sourcepub fn semantic_container(self, semantic_container: bool) -> Card
pub fn semantic_container(self, semantic_container: bool) -> Card
Dart Card(semanticContainer:).
Trait Implementations§
Source§impl StatelessWidget for Card
impl StatelessWidget for Card
Source§fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
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 debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
this is PreferredSizeWidget: a widget that implements PreferredSizeWidget
answers with itself, which is what a parent asking an erased child for its preferred
size reads.Auto Trait Implementations§
impl !RefUnwindSafe for Card
impl !Send for Card
impl !Sync for Card
impl !UnwindSafe for Card
impl Forget for Card
impl Freeze for Cardwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn ShapeBorder> is !null: Freeze,
PhantomData<RcInner<dyn ShapeBorder>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for Card
impl Unpin for Card
impl UnsafeUnpin for Cardwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ShapeBorder>>: 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<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.