NotificationBadgeWidget class

A badge widget that automatically displays the current notification count.

This widget uses AppCubit state to display the app's unread notification count. It automatically updates when the count changes and uses Material Design 3 Badge for proper theming.

Automatic Mode (no count parameter):

NotificationBadgeWidget(
  child: Icon(Icons.notifications),
)
// Automatically shows AppState.unreadNotificationCount

Manual Mode (with count parameter):

NotificationBadgeWidget(
  count: 5,
  child: Icon(Icons.shopping_cart),
)
// Shows the specific count you provide

Custom styling:

NotificationBadgeWidget(
  maxCount: 99,              // Shows "99+" for counts > 99
  hideWhenZero: true,        // Hides badge when count is 0
  backgroundColor: Colors.red,
  textColor: Colors.white,
  child: IconButton(
    icon: Icon(Icons.mail),
    onPressed: () {},
  ),
)

Custom alignment:

NotificationBadgeWidget(
  alignment: AlignmentDirectional(-12, -4),  // Top-left
  offset: Offset(4, -4),     // Fine-tune position
  child: YourWidget(),
)
Inheritance
Available extensions

Constructors

NotificationBadgeWidget({Key? key, int? count, required Widget child, bool hideWhenZero = true, int maxCount = 99, Color? backgroundColor, Color? textColor, AlignmentGeometry? alignment, Offset? offset, TextStyle? textStyle, bool isLabelVisible = true})
const

Properties

alignment AlignmentGeometry?
Alignment of the badge relative to the child. Defaults to top-right corner: AlignmentDirectional(12, -4). Common values:
final
backgroundColor Color?
Background color of the badge. Defaults to theme's error color (typically red).
final
child Widget
The widget to display the badge on top of.
final
count int?
The count to display in the badge.
final
hashCode int
The hash code for this object.
no setterinherited
hideWhenZero bool
Whether to hide the badge when count is zero. Defaults to true.
final
isLabelVisible bool
Whether the badge is enabled. When false, only the child is displayed without the badge. Defaults to true.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
maxCount int
Maximum count to display before showing overflow indicator. For example, if maxCount is 99, counts above 99 will show as "99+". Defaults to 99.
final
offset Offset?
Additional offset from the aligned position. Useful for fine-tuning placement.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textColor Color?
Text color of the count. Defaults to theme's onError color (typically white).
final
textStyle TextStyle?
Text style for the count. If not provided, uses Flutter's default badge text style.
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, int wrapWidth = 65}) 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
withUpdateDebugControls() Widget

Available on Widget, provided by the AppUpdateDebugExtension extension

Wraps this widget with debug controls if in debug mode

Operators

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