TBadge class
A versatile badge widget that displays status dots, counts, text pills, or custom widget overlays on any widget.
TBadge is designed to be fully generic:
- It can wrap any widget (Icon, Text, TAvatar, TButton, Container, Card, etc.).
- It can display any content via the generic badge parameter (
int,num,String,bool, orWidget), or via dedicated parameters/constructors (count, label, dot, badgeWidget). - It can also be rendered standalone without a child widget via TBadge.standalone.
Basic Usage (Wrapping an Icon or Avatar)
TBadge(
count: 5,
child: Icon(Icons.notifications),
)
TBadge(
dot: true,
child: TAvatar(name: 'Jane Doe'),
)
Generic / Dynamic Badge Content
TBadge(
badge: 12, // int count
child: Icon(Icons.mail),
)
TBadge(
badge: 'NEW', // text pill
color: AppColors.primary,
child: Text('Dashboard'),
)
TBadge(
badge: true, // status dot
alignment: Alignment.bottomRight,
child: TAvatar(name: 'JD'),
)
Named Constructors
- TBadge.count — for notification counts with auto overflow (e.g.
99+). - TBadge.dot — for status dots.
- TBadge.label — for text badges like "NEW", "HOT", "BETA".
- TBadge.custom — for arbitrary widget badge overlays.
- TBadge.standalone — renders the badge itself without a child wrapper.
- Inheritance
- Available extensions
Constructors
- TBadge({Key? key, Widget? child, dynamic badge, int? count, String? label, bool dot = false, Widget? badgeWidget, Alignment alignment = Alignment.topRight, Offset? offset, Color? color, Color? textColor, TextStyle? textStyle, Color? borderColor, double borderWidth = 1.5, bool showBorder = true, int maxCount = 99, bool hideZero = true, TSize? size, EdgeInsetsGeometry? padding, BorderRadiusGeometry? borderRadius, BoxShape? shape})
-
Creates a versatile badge.
const
- TBadge.count({Key? key, Widget? child, required int count, Alignment alignment = Alignment.topRight, Offset? offset, Color? color, Color? textColor, TextStyle? textStyle, Color? borderColor, double borderWidth = 1.5, bool showBorder = true, int maxCount = 99, bool hideZero = true, TSize? size, EdgeInsetsGeometry? padding, BorderRadiusGeometry? borderRadius, BoxShape? shape})
-
Creates a numerical count badge.
const
- TBadge.custom({Key? key, Widget? child, required Widget badgeWidget, Alignment alignment = Alignment.topRight, Offset? offset, })
-
Creates a badge with a custom widget overlay.
const
- TBadge.dot({Key? key, Widget? child, Alignment alignment = Alignment.topRight, Offset? offset, Color? color, Color? borderColor, double borderWidth = 1.5, bool showBorder = true, TSize? size})
-
Creates a status dot badge.
const
- TBadge.label({Key? key, Widget? child, required String label, Alignment alignment = Alignment.topRight, Offset? offset, Color? color, Color? textColor, TextStyle? textStyle, Color? borderColor, double borderWidth = 1.5, bool showBorder = true, TSize? size, EdgeInsetsGeometry? padding, BorderRadiusGeometry? borderRadius, BoxShape? shape})
-
Creates a text label badge (e.g. "NEW", "HOT", "SALE").
const
- TBadge.standalone({Key? key, dynamic badge, int? count, String? label, bool dot = false, Widget? badgeWidget, Color? color, Color? textColor, TextStyle? textStyle, Color? borderColor, double borderWidth = 1.5, bool showBorder = true, int maxCount = 99, bool hideZero = true, TSize? size, EdgeInsetsGeometry? padding, BorderRadiusGeometry? borderRadius, BoxShape? shape})
-
Creates a standalone badge widget without a child wrapper.
const
Properties
- alignment → Alignment
-
The alignment position of the badge relative to child.
final
- badge → dynamic
-
Dynamic badge content: supports int/num (count), String (label),
bool (dot indicator when true), or a custom Widget.
final
- badgeWidget → Widget?
-
A custom widget to use as the badge overlay.
final
- borderColor → Color?
-
The border color surrounding the badge.
final
- borderRadius → BorderRadiusGeometry?
-
Border radius for rounded badges.
final
- borderWidth → double
-
The width of the border surrounding the badge.
final
- child → Widget?
-
The target widget to display the badge on.
final
- color → Color?
-
The background color of the badge.
final
- count → int?
-
The numerical value to display in the badge.
final
- dot → bool
-
Whether to display a small status dot instead of text/count.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
Whether the badge is completely hidden.
final
- hideZero → bool
-
Whether to hide the badge when numerical count is 0.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String?
-
A custom text label to display in the badge.
final
- maxCount → int
-
The maximum count to display before showing a '+' sign.
final
- offset → Offset?
-
Optional fine-grained offset to adjust badge positioning.
final
- padding → EdgeInsetsGeometry?
-
Padding applied inside count or label badges.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shape → BoxShape?
-
Shape of the badge container.
final
- showBorder → bool
-
Whether to render a border around the badge.
final
- size → TSize?
-
The size configuration of the badge.
final
- textColor → Color?
-
The text color of the badge.
final
- textStyle → TextStyle?
-
Custom text style for count or label badges.
final
Methods
-
box(
{double minW = 0.0, double minH = 0.0, double maxW = double.infinity, double maxH = double.infinity}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a ConstrainedBox to apply layout constraints. -
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
center(
{bool when = true}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a Center widget. -
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
-
expanded(
{int flex = 1}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in an Expanded widget. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
padding(
[double left = 0.0, double top = 0.0, double right = 0.0, double bottom = 0.0]) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a Padding with flexible edge control. -
paddingSymmetric(
{double h = 0.0, double v = 0.0}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a Padding with symmetric horizontal and vertical spacing. -
size(
{double? w, double? h}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a SizedBox to apply fixed width and/or height. -
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
-
visible(
bool visible, {bool maintainState = false}) → Widget -
Available on Widget, provided by the WidgetX extension
Wraps this widget in a Visibility widget. -
when(
bool condition) → Widget -
Available on Widget, provided by the WidgetX extension
Returns this widget ifconditionis true, otherwise returns SizedBox.shrink(). Usage: Text('Hello').when(isVisible)
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited