The Badge
widget in Flutter is a small graphical element used to represent a notification, status, or count. Badges are often used to show a count, such as the number of unread notifications, or to indicate a status, such as a pending task.
Here’s an example of using the Badge
widget in Flutter:
Badge(
badgeContent: Text('3'),
child: Icon(Icons.notifications),
)
In this example, the Badge
widget is used to wrap an Icon
widget. The badgeContent
property is set to a Text
widget that displays the count of unread notifications.
Here are some of the key properties of the Badge
widget:
badgeContent
: The content to display in the badge. This can be any widget, but it’s usually aText
widget.child
: The child widget to wrap in the badge. This is usually anIcon
widget.shape
: The shape of the badge. By default, the badge is circular. You can also use other shapes, such asCircleBorder
orRoundedRectangleBorder
.padding
: The padding around the badge content.position
: The position of the badge relative to the child widget. You can use theBadgePosition
enumeration to choose from several positions, such astopRight
,bottomLeft
, andbottomRight
.color
: The color of the badge background. By default, the color is red.