TextStatusBadge class
A customizable badge widget for displaying status text with automatic text color adjustment based on background luminance.
This widget supports multiple ways to specify colors:
- Direct color values via color, backgroundColor, and borderColor
- Theme token keys via textColorKey, backgroundColorKey, and borderColorKey
- Hex color strings (e.g., '#FF0000') via the key parameters
The text color automatically adjusts to black or white based on the background color's luminance for optimal readability.
Usage:
// Using theme tokens
TextStatusBadge(
status: 'Active',
backgroundColorKey: 'success',
textColorKey: 'onSuccess',
)
// Using hex colors
TextStatusBadge(
status: 'Pending',
backgroundColorKey: '#FFA500',
)
// Using direct colors
TextStatusBadge(
status: 'Inactive',
backgroundColor: Colors.grey,
color: Colors.white,
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- TextStatusBadge
Constructors
- TextStatusBadge({Key? key, required String status, Color? backgroundColor, Color? color = const Color(0xFF000000), String? textColorKey, String? backgroundColorKey, Color? borderColor, String? borderColorKey})
-
Creates a TextStatusBadge widget.
const
Properties
- backgroundColor → Color?
-
The explicit background color for the badge.
final
- backgroundColorKey → String?
-
Theme token key or hex color string for the background color.
final
- borderColor → Color?
-
The explicit border color for the badge.
final
- borderColorKey → String?
-
Theme token key or hex color string for the border color.
final
- color → Color?
-
The explicit text color for the status text.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → String
-
The status text to display in the badge.
final
- textColorKey → String?
-
Theme token key or hex color string for the text color.
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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getTextColorBasedOnBackground(
Color backgroundColor) → Color - Determines the appropriate text color (black or white) based on the background color's luminance for optimal readability.