cardBadgeWidget function

Widget? cardBadgeWidget(
  1. CardBadge badge,
  2. ResourceRecord record,
  3. BuildContext context
)

One badge slot's widget, or null when the field has no renderable value.

A boolean value becomes a BooleanBadge — detected on the raw typed value, upstream of cardFieldText's toString(): after stringification a real bool and the string "true" are indistinguishable, and the string must keep rendering as an ordinary text badge. Every other type takes the text path.

Implementation

Widget? cardBadgeWidget(
  CardBadge badge,
  ResourceRecord record,
  BuildContext context,
) {
  if (record.get<Object>(badge.field) case final raw? when raw is bool) {
    return BooleanBadge(value: raw, colors: badge.colors);
  }

  if (cardFieldText(record, context, badge.field, isolate: false)
      case final value?) {
    return SemanticBadge(value: value, colors: badge.colors);
  }

  return null;
}