buildIconButton function
Implementation
Widget buildIconButton(BuildContext context, OpenUiNode node) {
final theme = node.theme;
final icon = node.props.string('icon') ?? '';
final given = _nonEmpty(node.props.string('label'));
final label = given ?? icon;
final variant = node.props.string('variant') ?? 'outline';
final enabled = !node.isStreaming;
return Align(
alignment: AlignmentDirectional.centerStart,
widthFactor: 1,
heightFactor: 1,
child: ActionGate(
node: node,
prop: 'action',
enabled: enabled,
label: (_) => label,
builder: (context, status, onTap) {
final phase = status?.phase;
Widget button = Press(
onTap: onTap,
builder: (hovered, pressed) {
final overlay = pressed
? theme.pressed
: hovered
? theme.hover
: null;
final (background, foreground, border) = switch (variant) {
'ghost' => (
overlay,
hovered || pressed ? theme.ink : theme.muted,
Colors.transparent,
),
'solid' => (
hovered && !pressed ? theme.inkHover : theme.ink,
theme.onInk,
theme.ink,
),
_ => (
Color.alphaBlend(overlay ?? Colors.transparent, theme.canvas),
theme.ink,
theme.border,
),
};
return Opacity(
opacity: onTap != null ? 1 : 0.4,
child: AnimatedContainer(
duration: _buttonFade,
curve: Curves.ease,
width: 34,
height: 34,
alignment: Alignment.center,
decoration: BoxDecoration(
color: background,
shape: BoxShape.circle,
border: Border.all(color: border),
),
child: switch (phase) {
ActionPhase.pending ||
ActionPhase.unknown => _Spinner(size: 16, color: foreground),
ActionPhase.done => Glyph(
'check',
size: 16,
color: foreground,
),
ActionPhase.failed => Glyph(
Glyph.has(context, 'circle-alert')
? 'circle-alert'
: 'info',
size: 16,
color: theme.status['danger'] ?? foreground,
),
_ => Glyph(icon, size: 16, color: foreground),
},
),
);
},
);
if (given != null) {
button = Tooltip(
message: given,
decoration: BoxDecoration(
color: theme.ink,
borderRadius: BorderRadius.circular(theme.radii.sm),
),
textStyle: _text(
theme,
size: theme.fontSizeOf('Tooltip', 12),
color: theme.onInk,
),
child: button,
);
}
return Semantics(
container: true,
button: true,
enabled: onTap != null,
label: label,
child: button,
);
},
),
);
}