Badge.count constructor

Badge.count({
  1. Key? key,
  2. Color? backgroundColor,
  3. Color? textColor,
  4. double? smallSize,
  5. double? largeSize,
  6. TextStyle? textStyle,
  7. EdgeInsetsGeometry? padding,
  8. AlignmentGeometry? alignment,
  9. Offset? offset,
  10. required int count,
  11. int maxCount = 999,
  12. bool isLabelVisible = true,
  13. Widget? child,
})

Convenience constructor for creating a badge with a numeric label based on count.

Initializes label with a Text widget that shows:

  • the count value if it is less than or equal to maxCount,
  • otherwise, shows 'maxCount+'.

For example, if count is 1000 and maxCount is 99, the label will display '99+'.

Implementation

Badge.count({
  super.key,
  this.backgroundColor,
  this.textColor,
  this.smallSize,
  this.largeSize,
  this.textStyle,
  this.padding,
  this.alignment,
  this.offset,
  required int count,
  int maxCount = 999,
  this.isLabelVisible = true,
  this.child,
}) : assert(count >= 0, 'count must be non-negative'),
     assert(maxCount > 0, 'maxCount must be positive'),
     label = Text(count > maxCount ? '$maxCount+' : '$count');