Badge class

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 smallSize diameter filled circle. Otherwise this is a StadiumBorder shaped "large" badge with height largeSize.

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.

This example shows how to create a Badge with label and count wrapped on an icon in an IconButton.
link

To create a local project with this code sample, run:
flutter create --sample=material.Badge.1 mysample

Inheritance

Constructors

Badge({Key? key, Color? backgroundColor, Color? textColor, double? smallSize, double? largeSize, TextStyle? textStyle, EdgeInsetsGeometry? padding, AlignmentGeometry? alignment, Offset? offset, Widget? label, bool isLabelVisible = true, Widget? child})
Create a Badge that stacks label on top of child.
const
Badge.count({Key? key, Color? backgroundColor, Color? textColor, double? smallSize, double? largeSize, TextStyle? textStyle, EdgeInsetsGeometry? padding, AlignmentGeometry? alignment, Offset? offset, required int count, bool isLabelVisible = true, Widget? child})
Convenience constructor for creating a badge with a numeric label with 1-3 digits based on count.

Properties

alignment AlignmentGeometry?
Combined with offset to determine the location of the label relative to the child.
final
backgroundColor Color?
The badge's fill color.
final
child Widget?
The widget that the badge is stacked on top of.
final
hashCode int
The hash code for this object.
no setterinherited
isLabelVisible bool
If false, the badge's label is not included.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
label Widget?
The badge's content, typically a Text widget that contains 1 to 4 characters.
final
largeSize double?
The badge's height if label is non-null.
final
offset Offset?
Combined with alignment to determine the location of the label relative to the child.
final
padding EdgeInsetsGeometry?
The padding added to the badge's label.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
smallSize double?
The diameter of the badge if label is null.
final
textColor Color?
The color of the badge's label text.
final
textStyle TextStyle?
The DefaultTextStyle for the badge's label.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited