Skip to main content

Icon

Struct Icon 

Source
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 from AssetImages or other ImageProviders.

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:

  • fill, for controlling fill.
  • weight, for controlling stroke weight.
  • grade, for controlling stroke weight in a more granular way.
§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.

§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

Source

pub fn new(icon: Option<IconData>) -> Icon

Creates an icon; Dart’s optional named arguments are the setters.

Source

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

Dart Icon(key:).

Source

pub fn size(self, size: f64) -> Icon

Dart Icon(size:).

Source

pub fn fill(self, fill: f64) -> Icon

Dart Icon(fill:); must be between 0.0 and 1.0, inclusive.

Source

pub fn weight(self, weight: f64) -> Icon

Dart Icon(weight:); must be greater than 0.

Source

pub fn grade(self, grade: f64) -> Icon

Dart Icon(grade:).

Source

pub fn optical_size(self, optical_size: f64) -> Icon

Dart Icon(opticalSize:); must be greater than 0.

Source

pub fn color(self, color: impl Into<AnyColor>) -> Icon

Dart Icon(color:).

Source

pub fn shadows(self, shadows: Vec<Shadow>) -> Icon

Dart Icon(shadows:).

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> Icon

Dart Icon(semanticLabel:).

Source

pub fn text_direction(self, text_direction: TextDirection) -> Icon

Dart Icon(textDirection:).

Source

pub fn apply_text_scaling(self, apply_text_scaling: bool) -> Icon

Dart Icon(applyTextScaling:).

Source

pub fn blend_mode(self, blend_mode: BlendMode) -> Icon

Dart Icon(blendMode:).

Source

pub fn font_weight(self, font_weight: FontWeight) -> Icon

Dart Icon(fontWeight:).

Trait Implementations§

Source§

impl Debug for Icon

Source§

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

Formats the value using the given formatter. Read more
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.

Source§

fn eq(&self, other: &Icon) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StatelessWidget for Icon

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 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_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>

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 Icon

§

impl !Send for Icon

§

impl !Sync for Icon

§

impl !UnwindSafe for Icon

§

impl Forget for Icon

§

impl Freeze for Icon
where *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
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin,

§

impl UnsafeUnpin for Icon

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>