Skip to main content

Badge

Struct Badge 

Source
pub struct Badge {
    pub key: Option<KeyRef>,
    pub background_color: Option<Color>,
    pub text_color: Option<Color>,
    pub small_size: Option<f64>,
    pub large_size: Option<f64>,
    pub text_style: Option<TextStyle>,
    pub padding: Option<EdgeInsetsGeometry>,
    pub alignment: Option<AlignmentGeometry>,
    pub offset: Option<Offset>,
    pub label: Option<WidgetRef>,
    pub is_label_visible: bool,
    pub child: Option<WidgetRef>,
    /* private fields */
}
Expand description

A Material Design “badge”.

A badge’s label conveys a small amount of information about its child, like a count or status. If the label is null then this is a “small” badge that’s displayed as a small_size diameter filled circle. Otherwise this is a StadiumBorder shaped “large” badge with height large_size.

Badges are typically used to decorate the icon within a BottomNavigationBarItem or a NavigationRailDestination or a button’s icon, as in TextButton::icon. The badge’s default configuration is intended to work well with a default sized (24) Icon.

Fields§

§key: Option<KeyRef>§background_color: Option<Color>

The badge’s fill color.

Defaults to the BadgeTheme’s background color, or ColorScheme::error if the theme value is null.

§text_color: Option<Color>

The color of the badge’s label text.

This color overrides the color of the label’s text_style.

Defaults to the BadgeTheme’s foreground color, or ColorScheme::on_error if the theme value is null.

§small_size: Option<f64>

The diameter of the badge if label is null.

Defaults to the BadgeTheme’s small size, or 6 if the theme value is null.

§large_size: Option<f64>

The badge’s height if label is non-null.

Defaults to the BadgeTheme’s large size, or 16 if the theme value is null. If the default value is overridden then it may be useful to also override padding and alignment.

§text_style: Option<TextStyle>

The DefaultTextStyle for the badge’s label.

The text style’s color is overwritten by the text_color.

This value is only used if label is non-null.

Defaults to the BadgeTheme’s text style, or the overall theme’s TextTheme::label_small if the badge theme’s value is null. If the default text style is overridden then it may be useful to also override large_size, padding, and alignment.

§padding: Option<EdgeInsetsGeometry>

The padding added to the badge’s label.

This value is only used if label is non-null.

Defaults to the BadgeTheme’s padding, or 4 pixels on the left and right if the theme’s value is null.

§alignment: Option<AlignmentGeometry>

Combined with offset to determine the location of the label relative to the child.

The alignment positions the label in the same way a child of an Align widget is positioned, except that, the alignment is resolved as if the label was a large_size square and offset is added to the result.

This value is only used if label is non-null.

Defaults to the BadgeTheme’s alignment, or AlignmentDirectional::TOP_END if the theme’s value is null.

§offset: Option<Offset>

Combined with alignment to determine the location of the label relative to the child.

This value is only used if label is non-null.

Defaults to the BadgeTheme’s offset, or if the theme’s value is null then Offset(4, -4) for TextDirection::Ltr or Offset(-4, -4) for TextDirection::Rtl.

§label: Option<WidgetRef>

The badge’s content, typically a Text widget that contains 1 to 4 characters.

If the label is null then this is a “small” badge that’s displayed as a small_size diameter filled circle. Otherwise this is a StadiumBorder shaped “large” badge with height large_size.

A Badge::count has no label of its own: read it through effective_label.

§is_label_visible: bool

If false, the badge’s label is not included.

This flag is true by default. It’s intended to make it convenient to create a badge that’s only shown under certain conditions.

§child: Option<WidgetRef>

The widget that the badge is stacked on top of.

Typically this is an default sized Icon that’s part of a BottomNavigationBarItem or a NavigationRailDestination.

Implementations§

Source§

impl Badge

Source

pub fn new() -> Badge

Create a Badge that stacks label on top of child.

If label is null then just a filled circle is displayed. Otherwise the label is displayed within a StadiumBorder shaped area.

Source

pub fn count(count: i64) -> Badge

Convenience constructor for creating a badge with a numeric label based on count.

The label is a Text widget that shows:

  • the count value if it is less than or equal to max_count,
  • otherwise, shows ‘max_count+’.

For example, if count is 1000 and max_count is 99, the label will display ‘99+’.

The count must be non-negative.

Source

pub fn max_count(self, max_count: i64) -> Badge

Dart Badge.count(maxCount:): the largest count the label shows, 999 unless given. It only has a say in a Badge::count.

The max_count must be positive.

Source

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

Dart Badge(key:).

Source

pub fn background_color(self, background_color: Color) -> Badge

Dart Badge(backgroundColor:).

Source

pub fn text_color(self, text_color: Color) -> Badge

Dart Badge(textColor:).

Source

pub fn small_size(self, small_size: f64) -> Badge

Dart Badge(smallSize:).

Source

pub fn large_size(self, large_size: f64) -> Badge

Dart Badge(largeSize:).

Source

pub fn text_style(self, text_style: TextStyle) -> Badge

Dart Badge(textStyle:).

Source

pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Badge

Dart Badge(padding:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> Badge

Dart Badge(alignment:).

Source

pub fn offset(self, offset: Offset) -> Badge

Dart Badge(offset:).

Source

pub fn label<K>(self, label: impl IntoWidget<K>) -> Badge

Dart Badge(label:).

Source

pub fn is_label_visible(self, is_label_visible: bool) -> Badge

Dart Badge(isLabelVisible:).

Source

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

Dart Badge(child:).

Source

pub fn effective_label(&self) -> Option<WidgetRef>

Dart’s label field, as Badge.count fills it: a Text of the count, or of maxCount+ once the count is over it.

Trait Implementations§

Source§

impl Debug for Badge

Source§

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

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

impl Default for Badge

Source§

fn default() -> Badge

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

impl StatelessWidget for Badge

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 Badge

§

impl !Send for Badge

§

impl !Sync for Badge

§

impl !UnwindSafe for Badge

§

impl Forget for Badge

§

impl Freeze for Badge
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: 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 Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for Badge

§

impl Unpin for Badge
where Rc<dyn Key>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, *const u8 is !null: Unpin, Rc<Paint>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Badge

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>