OudsBadge class
Reference design version : 1.2.0
Badge is a UI element that emphasizes system notifications, status, or the categorization of an information, throughout colour only. Badge is rendered as a coloured shape, without icon, text or number; and its chosen size remains unchanged regardless of the changes of the interface size.
Badges have five statuses depending on the context of the information they represent. Each status is designed to convey a specific meaning and ensure clarity in communication.
A11Y recommendation: Provide a semanticsLabel semantics to clarify the meaning of this badge.
This widget provides three distinct types of badges, each created using a specific named constructor:
OudsBadge.standard: A simple dot, useful for indicating a status or the presence of new, unquantified items.OudsBadge.count: Displays a numerical value or short text. The text is only visible formediumandlargesizes. For numerical labels of 100 or more, it displays "+99".OudsBadge.icon: Displays an icon within the badge. The icon is only visible formediumandlargesizes.
This API replaces the previous generic constructor and deprecated status model.
Migration overview
1) Use named constructors
Replace the deprecated default constructor:
OudsBadge(...)with one of:OudsBadge.standard(...)OudsBadge.count(...)OudsBadge.icon(...)
2) Replace OudsBadgeStatus with OudsIconStatus
OudsBadgeStatus is deprecated and will be removed.
Use OudsIconStatus subclasses to define badge visual semantics.
3) Remove icon parameter
The icon parameter is deprecated and will be removed.
Icon selection must now be driven by status (OudsIconStatus):
- Functional statuses (
Positive,Info,Warning,Negative) provide fixed icons. - Contextual statuses (
Neutral,Accent) can carry a custom icon asset.
Status model
New status type:
- Neutral (optional custom icon)
- Accent (optional custom icon)
- Positive (fixed functional icon)
- Info (fixed functional icon)
- Warning (fixed functional icon)
- Negative (fixed functional icon)
This unifies:
- background color
- icon choice
- icon/text foreground color
Behavior notes
counttext is visible only for OudsBadgeSize.medium and OudsBadgeSize.large.- Numeric values
>= 100are formatted as+99. iconis visible only for OudsBadgeSize.medium and OudsBadgeSize.large.- For accessibility, always provide semanticsLabel.
Parameters :
-
status : The badge's status, influencing its color and style (e.g., negative, positive, warning). Used by
OudsBadge.standardandOudsBadge.count. -
size : The size of the badge, such as medium, large, etc., to fit various visual needs.
-
label : An optional text to display inside the badge, often used for numbers or status texts. Used by
OudsBadge.count -
icon : An optional SVG asset name to display an icon within the badge, complementing or replacing the label.
-
status : The status of the badge. The background color of the badge and the icon color are based on this status. Used by
OudsBadge.iconThere are two types of status: -
child : A custom widget to insert inside the badge for advanced customization.
-
semanticsLabel: An optional accessibility label read by screen readers, providing a clear description of the badge's meaning (e.g., "5 new notifications", "Error", "Success").
Styling details :
- The size and margins are adjusted according to the badge size via OudsBadgeSize.
The badge's appearance can be customized using parameters for status, size, and content.
Usage examples:
Standard badge
OudsBadge.standard(
status: Negative(),
size: OudsBadgeSize.medium,
semanticsLabel: 'Erreur',
child: const Icon(Icons.mail),
)
Count badge
OudsBadge.count(
label: '12',
status: Info(),
size: OudsBadgeSize.large,
semanticsLabel: '12 notifications',
child: const Icon(Icons.notifications),
)
Icon badge with functional status icon
OudsBadge.icon(
status: Warning(),
size: OudsBadgeSize.large,
semanticsLabel: 'Avertissement',
child: const Icon(Icons.settings),
)
Icon badge with custom icon (Neutral/Accent)
OudsBadge.icon(
status: Accent(icon: 'assets/heart-empty.svg'),
size: OudsBadgeSize.large,
semanticsLabel: 'Favorite',
child: const Icon(Icons.person),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- OudsBadge
Constructors
- OudsBadge({Key? key, OudsBadgeStatus? status, OudsBadgeSize? size = OudsBadgeSize.medium, String? label, @Deprecated('icon is now defined by status (OudsIconStatus). Use Accent(icon: ...) or Neutral(icon: ...) for custom icons.') String? icon, Widget? child, bool enabled = true, String? semanticsLabel})
-
⚠️ DEPRECATED: Use OudsBadge.standard, OudsBadge.icon, or OudsBadge.count constructors instead.
const
- OudsBadge.count({Key? key, String? label, OudsBadgeSize? size = OudsBadgeSize.medium, Widget? child, bool enabled = true, String? semanticsLabel, OudsIconStatus? status})
-
const
- OudsBadge.icon({Key? key, OudsBadgeSize? size = OudsBadgeSize.medium, Widget? child, bool enabled = true, String? semanticsLabel, OudsIconStatus? status, bool withIcon = true})
-
const
- OudsBadge.standard({Key? key, OudsBadgeSize? size = OudsBadgeSize.medium, Widget? child, bool enabled = true, String? semanticsLabel, OudsIconStatus? status})
-
const
Properties
- child → Widget?
-
final
- enabled → bool
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- icon → String?
-
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsLabel → String?
-
final
- size → OudsBadgeSize?
-
final
- status → OudsIconStatus?
-
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< OudsBadge> -
Creates the mutable state for this widget at a given location in the tree.
override
-
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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited