badgeCriteriaLabel function
- AppLocalizations l10n,
- Badge badge
Localized description of what a Badge is awarded for.
Badge is a domain entity — plain Dart with no Flutter dependency — so its
criteriaLabel getter returns English. This is the presentation-layer
equivalent the badge lists render, the same split used by
certTargetLabel and
orgRoleLabel.
The criteria map is stored as JSON, so its values arrive dynamically typed
and are interpolated as strings; only count is parsed to an int, because
the session criterion needs a plural category.
The session criterion uses an ICU plural where the entity getter appends a
literal (s), so this renders "Complete 1 session" rather than
"Complete 1 session(s)".
Implementation
String badgeCriteriaLabel(AppLocalizations l10n, Badge badge) {
final criteria = badge.criteria;
switch (criteria['type'] as String?) {
case 'first_session':
final raw = criteria['count'];
final count = raw is int ? raw : int.tryParse('$raw') ?? 1;
return l10n.orgBadgeCriteriaSessions(count);
case 'streak_days':
return l10n.orgBadgeCriteriaStreak('${criteria['days']}');
case 'mastery_level':
return l10n.orgBadgeCriteriaMastery('${criteria['level']}');
case 'all_assignments':
return l10n.orgBadgeCriteriaAssignments;
case 'total_xp':
return l10n.orgBadgeCriteriaXp('${criteria['amount']}');
default:
return l10n.orgBadgeCriteriaUnknown;
}
}