pub struct Icon {Show 14 fields
pub key: Option<KeyRef>,
pub icon: Option<IconData>,
pub size: Option<f64>,
pub fill: Option<f64>,
pub weight: Option<f64>,
pub grade: Option<f64>,
pub optical_size: Option<f64>,
pub color: Option<AnyColor>,
pub shadows: Option<Vec<Shadow>>,
pub semantic_label: Option<String>,
pub text_direction: Option<TextDirection>,
pub apply_text_scaling: Option<bool>,
pub blend_mode: Option<BlendMode>,
pub font_weight: Option<FontWeight>,
}Expand description
A graphical icon widget drawn with a glyph from a font described in
an IconData such as material’s predefined IconDatas in Icons.
Icons are not interactive. For an interactive icon, consider material’s
IconButton.
There must be an ambient Directionality widget when using Icon.
Typically this is introduced automatically by the WidgetsApp or
MaterialApp.
This widget assumes that the rendered icon is squared. Non-squared icons may render incorrectly.
This example shows how to create a Row of Icons in different colors and
sizes:
Row::new().children(vec![
Icon::new(Some(Icons::FAVORITE)).color(PINK).size(24.0).into_widget(),
Icon::new(Some(Icons::AUDIOTRACK)).color(GREEN).size(30.0).into_widget(),
Icon::new(Some(Icons::BEACH_ACCESS)).color(BLUE).size(36.0).into_widget(),
])See also:
IconButton, for interactive icons.Icons, for the list of available Material Icons for use with this class.IconTheme, which provides ambient configuration for icons.ImageIcon, for showing icons fromAssetImages or otherImageProviders.
Fields§
§key: Option<KeyRef>§icon: Option<IconData>The icon to display. The available icons are described in Icons.
The icon can be None, in which case the widget will render as an empty
space of the specified size.
size: Option<f64>The size of the icon in logical pixels.
Icons occupy a square with width and height equal to size.
Defaults to the nearest IconTheme’s IconThemeData::size.
If this Icon is being placed inside an IconButton, then use
IconButton.iconSize instead, so that the IconButton can make the splash
area the appropriate size as well. The IconButton uses an IconTheme to
pass down the size to the Icon.
fill: Option<f64>The fill for drawing the icon.
Requires the underlying icon font to support the FILL FontVariation
axis, otherwise has no effect. Variable font filenames often indicate
the supported axes. Must be between 0.0 (unfilled) and 1.0 (filled),
inclusive.
Can be used to convey a state transition for animation or interaction.
Defaults to nearest IconTheme’s IconThemeData::fill.
See also:
weight, for controlling stroke weight.grade, for controlling stroke weight in a more granular way.optical_size, for controlling optical size.
weight: Option<f64>The stroke weight for drawing the icon.
Requires the underlying icon font to support the wght FontVariation
axis, otherwise has no effect. Variable font filenames often indicate
the supported axes. Must be greater than 0.
Defaults to nearest IconTheme’s IconThemeData::weight.
See also:
fill, for controlling fill.grade, for controlling stroke weight in a more granular way.optical_size, for controlling optical size.
grade: Option<f64>The grade (granular stroke weight) for drawing the icon.
Requires the underlying icon font to support the GRAD FontVariation
axis, otherwise has no effect. Variable font filenames often indicate
the supported axes. Can be negative.
Grade and weight both affect a symbol’s stroke weight
(thickness), but grade has a smaller impact on the size of the symbol.
Grade is also available in some text fonts. One can match grade levels between text and symbols for a harmonious visual effect. For example, if the text font has a -25 grade value, the symbols can match it with a suitable value, say -25.
Defaults to nearest IconTheme’s IconThemeData::grade.
See also:
fill, for controlling fill.weight, for controlling stroke weight in a less granular way.optical_size, for controlling optical size.
optical_size: Option<f64>The optical size for drawing the icon.
Requires the underlying icon font to support the opsz FontVariation
axis, otherwise has no effect. Variable font filenames often indicate
the supported axes. Must be greater than 0.
For an icon to look the same at different sizes, the stroke weight (thickness) must change as the icon size scales. Optical size offers a way to automatically adjust the stroke weight as icon size changes.
Defaults to nearest IconTheme’s IconThemeData::optical_size.
See also:
color: Option<AnyColor>The color to use when drawing the icon.
Defaults to the nearest IconTheme’s IconThemeData::color.
The color (whether specified explicitly here or obtained from the
IconTheme) will be further adjusted by the nearest IconTheme’s
IconThemeData::opacity.
shadows: Option<Vec<Shadow>>A list of Shadows that will be painted underneath the icon.
Multiple shadows are supported to replicate lighting from multiple light sources.
Shadows must be in the same order for Icon to be considered as
equivalent as order produces differing transparency.
Defaults to the nearest IconTheme’s IconThemeData::shadows.
semantic_label: Option<String>Semantic label for the icon.
Announced by assistive technologies (e.g TalkBack/VoiceOver). This label does not show in the UI.
SemanticsProperties::label, which is set tosemantic_labelin the underlyingSemanticswidget.
text_direction: Option<TextDirection>The text direction to use for rendering the icon.
If this is None, the ambient Directionality is used instead.
Some icons follow the reading direction. For example, “back” buttons point
left in left-to-right environments and right in right-to-left
environments. Such icons have their IconData::match_text_direction field
set to true, and the Icon widget uses the
text_direction to determine the orientation in which to draw
the icon.
This property has no effect if the icon’s
IconData::match_text_direction field is false, but for consistency a text direction
value must always be specified, either directly using this property or using
Directionality.
apply_text_scaling: Option<bool>Whether to scale the size of this widget using the ambient MediaQuery’s
TextScaler.
This is specially useful when you have an icon associated with a text, as scaling the text without scaling the icon would result in a confusing interface.
Defaults to the nearest IconTheme’s IconThemeData::apply_text_scaling.
blend_mode: Option<BlendMode>The BlendMode to apply to the foreground of the icon.
Defaults to BlendMode::SrcOver.
font_weight: Option<FontWeight>The typeface thickness to use when painting the text (e.g., bold).
Implementations§
Source§impl Icon
impl Icon
Sourcepub fn new(icon: Option<IconData>) -> Icon
pub fn new(icon: Option<IconData>) -> Icon
Creates an icon; Dart’s optional named arguments are the setters.
Sourcepub fn optical_size(self, optical_size: f64) -> Icon
pub fn optical_size(self, optical_size: f64) -> Icon
Dart Icon(opticalSize:); must be greater than 0.
Sourcepub fn semantic_label(self, semantic_label: impl Into<String>) -> Icon
pub fn semantic_label(self, semantic_label: impl Into<String>) -> Icon
Dart Icon(semanticLabel:).
Sourcepub fn text_direction(self, text_direction: TextDirection) -> Icon
pub fn text_direction(self, text_direction: TextDirection) -> Icon
Dart Icon(textDirection:).
Sourcepub fn apply_text_scaling(self, apply_text_scaling: bool) -> Icon
pub fn apply_text_scaling(self, apply_text_scaling: bool) -> Icon
Dart Icon(applyTextScaling:).
Sourcepub fn blend_mode(self, blend_mode: BlendMode) -> Icon
pub fn blend_mode(self, blend_mode: BlendMode) -> Icon
Dart Icon(blendMode:).
Sourcepub fn font_weight(self, font_weight: FontWeight) -> Icon
pub fn font_weight(self, font_weight: FontWeight) -> Icon
Dart Icon(fontWeight:).
Trait Implementations§
Source§impl PartialEq for Icon
Dart’s Widget.==, which is identity: an Icon equals only itself, so an Rc<Icon>
compares as the Dart reference does.
impl PartialEq for Icon
Dart’s Widget.==, which is identity: an Icon equals only itself, so an Rc<Icon>
compares as the Dart reference does.
Source§impl StatelessWidget for Icon
impl StatelessWidget for Icon
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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
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 Icon
impl !Send for Icon
impl !Sync for Icon
impl !UnwindSafe for Icon
impl Forget for Icon
impl Freeze for Iconwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
&'static dyn ColorExtension: Freeze,
*const RcInner<dyn ColorExtension> is !null: Freeze,
PhantomData<RcInner<dyn ColorExtension>>: Freeze,
PhantomData<Shadow>: Freeze,
impl Move for Icon
impl Unpin for Icon
impl UnsafeUnpin for Iconwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
&'static dyn ColorExtension: UnsafeUnpin,
*const RcInner<dyn ColorExtension> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin,
PhantomData<Shadow>: 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.