Skip to main content

Card

Struct Card 

Source
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:

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: bool

Whether 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: bool

Whether 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

Source

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.

Source

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.

Source

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.

Source

pub fn key(self, key: KeyRef) -> Card

Dart Card(key:).

Source

pub fn color(self, color: Color) -> Card

Dart Card(color:).

Source

pub fn shadow_color(self, shadow_color: Color) -> Card

Dart Card(shadowColor:).

Source

pub fn surface_tint_color(self, surface_tint_color: Color) -> Card

Dart Card(surfaceTintColor:).

Source

pub fn elevation(self, elevation: f64) -> Card

Dart Card(elevation:).

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Card

Dart Card(shape:).

Source

pub fn border_on_foreground(self, border_on_foreground: bool) -> Card

Dart Card(borderOnForeground:).

Source

pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> Card

Dart Card(margin:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Card

Dart Card(clipBehavior:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> Card

Dart Card(child:).

Source

pub fn semantic_container(self, semantic_container: bool) -> Card

Dart Card(semanticContainer:).

Trait Implementations§

Source§

impl Debug for Card

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Card

Source§

fn default() -> Card

Returns the “default value” for a type. Read more
Source§

impl StatelessWidget for Card

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Dart’s 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 Card
where *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
where Rc<dyn Key>: Unpin, Rc<dyn ShapeBorder>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Card
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatelessKind> for W
where W: StatelessWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>