pub struct Material {Show 14 fields
pub key: Option<KeyRef>,
pub child: Option<WidgetRef>,
pub type: MaterialType,
pub animate_color: bool,
pub elevation: f64,
pub color: Option<Color>,
pub shadow_color: Option<Color>,
pub surface_tint_color: Option<Color>,
pub text_style: Option<TextStyle>,
pub shape: Option<ShapeBorderRef>,
pub border_on_foreground: bool,
pub clip_behavior: Clip,
pub animation_duration: Duration,
pub border_radius: Option<BorderRadiusGeometry>,
}Expand description
A piece of material.
The Material widget is responsible for:
- Clipping: If
clip_behavioris notClip::None, Material clips its widget sub-tree to the shape specified byshape,type, andborder_radius. By default,clip_behaviorisClip::Nonefor performance considerations. SeeInkfor an example of how this affects clippingInkwidgets. - Elevation: Material elevates its widget sub-tree on the Z axis by
elevationpixels, and draws the appropriate shadow. - Ink effects: Material shows ink effects implemented by
InkFeatures likeInkSplashandInkHighlightbelow its children.
§The Material Metaphor
Material is the central metaphor in Material Design. Each piece of material exists at a given elevation, which influences how that piece of material visually relates to other pieces of material and how that material casts shadows.
Most user interface elements are either conceptually printed on a piece of
material or themselves made of material. Material reacts to user input using
InkSplash and InkHighlight effects. To
trigger a reaction on the material, use a MaterialInkController obtained via
Material::of.
In general, the features of a Material should not change over time (e.g. a
Material should not change its color,
shadow_color or type).
Changes to elevation, shadow_color and
surface_tint_color are animated
for animation_duration. Changes to shape are
animated if type is not MaterialType::Transparency and
ShapeBorder::lerp between the previous and next shape values is
supported. Shape changes are also animated for
animation_duration.
§Shape
The shape for material is determined by shape, type,
and border_radius.
- If
shapeis non null, it determines the shape. - If
shapeis null andborder_radiusis non null, the shape is a rounded rectangle, with corners specified byborder_radius. - If
shapeandborder_radiusare null,typedetermines the shape as follows:MaterialType::Canvas: the default material shape is a rectangle.MaterialType::Card: the default material shape is a rectangle with rounded edges. The edge radii is specified byk_material_edges.MaterialType::Circle: the default material shape is a circle.MaterialType::Button: the default material shape is a rectangle with rounded edges. The edge radii is specified byk_material_edges.MaterialType::Transparency: the default material shape is a rectangle.
§Border
If shape is not null, then its border will also be painted (if any).
§Layout change notifications
If the layout changes (e.g. because there’s a list on the material, and it’s
been scrolled), a LayoutChangedNotification must be dispatched at the
relevant subtree. This in particular means that transitions (e.g.
SlideTransition) should not be placed inside Material widgets so as to
move subtrees that contain InkResponses,
InkWells, Inks, or other widgets that use the
InkFeature mechanism. Otherwise, in-progress ink features (e.g., ink splashes and ink
highlights) won’t move to account for the new layout.
§Painting over the material
Material widgets will often trigger reactions on their nearest material
ancestor. For example, ListTile.hoverColor triggers a reaction on the
tile’s material when a pointer is hovering over it. These reactions will be
obscured if any widget in between them and the material paints in such a
way as to obscure the material (such as setting a BoxDecoration.color on
a DecoratedBox). To avoid this behavior, use InkDecoration to
decorate the material itself.
See also:
MergeableMaterial, a piece of material that can split and re-merge.Card, a wrapper for aMaterialoftypeMaterialType::Card.- https://material.io/design/
- https://m3.material.io/styles/color/the-color-system/color-roles
Fields§
§key: Option<KeyRef>§child: Option<WidgetRef>The widget below this widget in the tree.
type: MaterialTypeThe kind of material to show (e.g., card or canvas). This affects the shape of the widget, the roundness of its corners if the shape is rectangular, and the default color.
animate_color: boolWhether the color should be animated.
elevation: f64The z-coordinate at which to place this material relative to its parent.
This controls the size of the shadow below the material and the opacity of the elevation overlay color if it is applied.
If this is non-zero, the contents of the material are clipped, because the widget conceptually defines an independent printed piece of material.
Defaults to 0. Changing this value will cause the shadow and the elevation
overlay or surface tint to animate over Material::animation_duration.
The value is non-negative.
See also:
ThemeData::use_material3which defines whether a surface tint or elevation overlay is used to indicate elevation.ThemeData::apply_elevation_overlay_colorwhich controls the whether an overlay color will be applied to indicate elevation.Material::colorwhich may have an elevation overlay applied.Material::shadow_colorwhich will be used for the color of a drop shadow.Material::surface_tint_colorwhich will be used as the overlay tint to show elevation.
color: Option<Color>The color to paint the material.
Must be opaque. To create a transparent piece of material, use
MaterialType::Transparency.
If ThemeData::use_material3 is true then an optional
surface_tint_color overlay may be applied on top of this
color to indicate elevation.
If ThemeData::use_material3 is false and ThemeData::apply_elevation_overlay_color
is true and ThemeData::brightness is Brightness::Dark then a
semi-transparent overlay color will be composited on top of this
color to indicate the elevation. This is no longer needed for Material
Design 3, which uses surface_tint_color.
By default, the color is derived from the type of material.
shadow_color: Option<Color>The color to paint the shadow below the material.
If null and ThemeData::use_material3 is true then ThemeData’s
ColorScheme::shadow will be used. If ThemeData::use_material3 is false
then ThemeData::shadow_color will be used.
To remove the drop shadow when elevation is greater than 0, set
shadow_color to Colors::TRANSPARENT.
See also:
ThemeData::use_material3, which determines the default value for this property if it is null.ThemeData::apply_elevation_overlay_color, which turns elevation overlay on or off for dark themes.
surface_tint_color: Option<Color>The color of the surface tint overlay applied to the material color to indicate elevation.
Material Design 3 introduced a new way for some components to indicate
their elevation by using a surface tint color overlay on top of the
base material color. This overlay is painted with an opacity that is
related to the elevation of the material.
If ThemeData::use_material3 is false, then this property is not used.
If ThemeData::use_material3 is true and
surface_tint_color is not null and not
Colors::TRANSPARENT, then it will be used to overlay the base
color with an opacity based on the elevation.
Otherwise, no surface tint will be applied.
See also:
ThemeData::use_material3, which turns this feature on.ElevationOverlay::apply_surface_tint, which is used to implement the tint.- https://m3.material.io/styles/color/the-color-system/color-roles which specifies how the overlay is applied.
text_style: Option<TextStyle>The typographical style to use for text within this material.
shape: Option<ShapeBorderRef>Defines the material’s shape as well its shadow.
If shape is non null, the border_radius is ignored and the
material’s clip boundary and shadow are defined by the shape.
A shadow is only displayed if the elevation is greater than
zero.
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: ClipThe content will be clipped (or not) according to this option.
Defaults to Clip::None.
animation_duration: DurationDefines the duration of animated changes for shape,
elevation, shadow_color,
surface_tint_color and the elevation overlay if it is
applied.
The default value is K_THEME_CHANGE_DURATION.
border_radius: Option<BorderRadiusGeometry>If non-null, the corners of this box are rounded by this
BorderRadiusGeometry value.
Otherwise, the corners specified for the current type of material
are used.
If shape is non null then the border radius is ignored.
Must be null if type is MaterialType::Circle.
Implementations§
Source§impl Material
impl Material
Sourcepub const DEFAULT_SPLASH_RADIUS: f64 = 35.0
pub const DEFAULT_SPLASH_RADIUS: f64 = 35.0
The default radius of an ink splash in logical pixels.
Sourcepub fn new() -> Material
pub fn new() -> Material
Creates a piece of material; Dart’s named arguments are the setters.
The elevation must be non-negative.
If a shape is specified, then the
border_radius property must be null and the
type property must not be MaterialType::Circle. If the
border_radius is specified, then the type
property must not be MaterialType::Circle. In both cases, these restrictions are
intended to catch likely errors.
Sourcepub fn type(self, type: MaterialType) -> Material
pub fn type(self, type: MaterialType) -> Material
Dart Material(type:).
Sourcepub fn shadow_color(self, shadow_color: Color) -> Material
pub fn shadow_color(self, shadow_color: Color) -> Material
Dart Material(shadowColor:).
Sourcepub fn surface_tint_color(self, surface_tint_color: Color) -> Material
pub fn surface_tint_color(self, surface_tint_color: Color) -> Material
Dart Material(surfaceTintColor:).
Sourcepub fn text_style(self, text_style: TextStyle) -> Material
pub fn text_style(self, text_style: TextStyle) -> Material
Dart Material(textStyle:).
Sourcepub fn border_radius(
self,
border_radius: impl Into<BorderRadiusGeometry>,
) -> Material
pub fn border_radius( self, border_radius: impl Into<BorderRadiusGeometry>, ) -> Material
Dart Material(borderRadius:).
Sourcepub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Material
pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> Material
Dart Material(shape:).
Sourcepub fn border_on_foreground(self, border_on_foreground: bool) -> Material
pub fn border_on_foreground(self, border_on_foreground: bool) -> Material
Dart Material(borderOnForeground:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Material
pub fn clip_behavior(self, clip_behavior: Clip) -> Material
Dart Material(clipBehavior:).
Sourcepub fn animation_duration(self, animation_duration: Duration) -> Material
pub fn animation_duration(self, animation_duration: Duration) -> Material
Dart Material(animationDuration:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> Material
pub fn child<K>(self, child: impl IntoWidget<K>) -> Material
Dart Material(child:).
Sourcepub fn animate_color(self, animate_color: bool) -> Material
pub fn animate_color(self, animate_color: bool) -> Material
Dart Material(animateColor:).
Sourcepub fn maybe_of(
app: &App,
context: BuildContext,
) -> Option<AnyMaterialInkController>
pub fn maybe_of( app: &App, context: BuildContext, ) -> Option<AnyMaterialInkController>
The ink controller from the closest instance of this class that
encloses the given context within the closest LookupBoundary.
This method can be expensive (it walks the element tree).
See also:
Material::of, which is similar to this method, but asserts if noMaterialancestor is found.
Sourcepub fn of(app: &App, context: BuildContext) -> AnyMaterialInkController
pub fn of(app: &App, context: BuildContext) -> AnyMaterialInkController
The ink controller from the closest instance of Material that encloses
the given context within the closest LookupBoundary.
If no Material widget ancestor can be found then this method panics.
This method can be expensive (it walks the element tree).
See also:
Material::maybe_of, which is similar to this method, but returns null if noMaterialancestor is found.
Trait Implementations§
Source§impl StatefulWidget for Material
impl StatefulWidget for Material
Source§type State = MaterialWidgetState
type State = MaterialWidgetState
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_state(&self) -> MaterialWidgetState
fn create_state(&self) -> MaterialWidgetState
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for Material
impl !Send for Material
impl !Sync for Material
impl !UnwindSafe for Material
impl Forget for Material
impl Freeze for Materialwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
&'static dyn ColorExtension: Freeze,
*const RcInner<dyn ColorExtension> is !null: Freeze,
PhantomData<RcInner<dyn ColorExtension>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
*const RcInner<Paint> is !null: Freeze,
PhantomData<RcInner<Paint>>: Freeze,
PhantomData<Shadow>: Freeze,
PhantomData<FontFeature>: Freeze,
PhantomData<FontVariation>: Freeze,
*const RcInner<dyn ShapeBorder> is !null: Freeze,
PhantomData<RcInner<dyn ShapeBorder>>: Freeze,
impl Move for Material
impl Unpin for Material
impl UnsafeUnpin for Materialwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
&'static dyn ColorExtension: UnsafeUnpin,
*const RcInner<dyn ColorExtension> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const RcInner<Paint> is !null: UnsafeUnpin,
PhantomData<RcInner<Paint>>: UnsafeUnpin,
PhantomData<Shadow>: UnsafeUnpin,
PhantomData<FontFeature>: UnsafeUnpin,
PhantomData<FontVariation>: UnsafeUnpin,
*const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ShapeBorder>>: 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.