buildBadge function
Implementation
Widget buildBadge(BuildContext context, OpenUiNode node) {
final theme = node.theme;
final tone = node.props.string('color');
final (background, foreground) = tone == 'info'
? (theme.statusSoft['info'], theme.status['info'])
: (theme.badgeSoft[tone], theme.badge[tone]);
final s = theme.styleOf('Badge', tone);
final color = s.foreground ?? foreground ?? theme.ink;
final icon = node.props.string('icon');
return Align(
alignment: AlignmentDirectional.centerStart,
widthFactor: 1,
heightFactor: 1,
child: Container(
constraints: const BoxConstraints(minHeight: 26),
padding:
s.padding ??
EdgeInsetsDirectional.fromSTEB(
Glyph.has(context, icon) ? 8 : 10,
3,
10,
3,
),
decoration: BoxDecoration(
color: s.background ?? background ?? theme.badgeNeutralSoft,
borderRadius: BorderRadius.circular(s.radius ?? theme.radii.full),
border: s.border == null ? null : Border.all(color: s.border!),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (Glyph.has(context, icon)) ...[
Glyph(icon, size: 14, color: color),
const SizedBox(width: 5),
],
Flexible(
child: Text(
node.props.string('text') ?? '',
softWrap: false,
overflow: TextOverflow.ellipsis,
style: _textStyle(
theme,
color: color,
size: theme.fontSizeOf('Badge', 13),
height: 18 / 13,
weight: theme.typography.medium,
),
),
),
],
),
),
);
}