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: boolIf 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
impl Badge
Sourcepub fn new() -> Badge
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.
Sourcepub fn count(count: i64) -> Badge
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
countvalue if it is less than or equal tomax_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.
Sourcepub fn max_count(self, max_count: i64) -> Badge
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.
Sourcepub fn background_color(self, background_color: Color) -> Badge
pub fn background_color(self, background_color: Color) -> Badge
Dart Badge(backgroundColor:).
Sourcepub fn text_color(self, text_color: Color) -> Badge
pub fn text_color(self, text_color: Color) -> Badge
Dart Badge(textColor:).
Sourcepub fn small_size(self, small_size: f64) -> Badge
pub fn small_size(self, small_size: f64) -> Badge
Dart Badge(smallSize:).
Sourcepub fn large_size(self, large_size: f64) -> Badge
pub fn large_size(self, large_size: f64) -> Badge
Dart Badge(largeSize:).
Sourcepub fn text_style(self, text_style: TextStyle) -> Badge
pub fn text_style(self, text_style: TextStyle) -> Badge
Dart Badge(textStyle:).
Sourcepub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Badge
pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Badge
Dart Badge(padding:).
Sourcepub fn alignment(self, alignment: AlignmentGeometry) -> Badge
pub fn alignment(self, alignment: AlignmentGeometry) -> Badge
Dart Badge(alignment:).
Sourcepub fn label<K>(self, label: impl IntoWidget<K>) -> Badge
pub fn label<K>(self, label: impl IntoWidget<K>) -> Badge
Dart Badge(label:).
Sourcepub fn is_label_visible(self, is_label_visible: bool) -> Badge
pub fn is_label_visible(self, is_label_visible: bool) -> Badge
Dart Badge(isLabelVisible:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> Badge
pub fn child<K>(self, child: impl IntoWidget<K>) -> Badge
Dart Badge(child:).
Sourcepub fn effective_label(&self) -> Option<WidgetRef>
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 StatelessWidget for Badge
impl StatelessWidget for Badge
Source§fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
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 debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
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 Badgewhere
*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
impl UnsafeUnpin for Badgewhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: 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 Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: 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.