buildCheckbox function
Implementation
Widget buildCheckbox(BuildContext context, OpenUiNode node) {
final theme = node.theme;
final label = node.props['label'] == null
? ''
: jsString(node.props['label']);
final f = _field(node, 'checked', label);
final checked = f.value == true;
final done = checked && node.props.boolean('lineThrough') == true;
final box = theme.styleOf('Checkbox');
final boxSize = box.size ?? 17;
final boxRadius = box.radius ?? 4;
return Align(
alignment: AlignmentDirectional.centerStart,
widthFactor: 1,
heightFactor: 1,
child: Semantics(
checked: checked,
label: label,
child: Press(
radius: boxRadius,
onTap: (_) => f.set(!checked),
builder: (hovered, pressed) => ConstrainedBox(
constraints: const BoxConstraints(minHeight: 28),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: boxSize,
height: boxSize,
alignment: Alignment.center,
decoration: BoxDecoration(
color: checked ? theme.ink : Colors.transparent,
borderRadius: BorderRadius.circular(boxRadius),
border: checked
? null
: Border.all(color: theme.muted, width: 1.5),
),
child: checked
? Glyph('check', size: 13, color: theme.onInk)
: null,
),
const SizedBox(width: 9),
Flexible(
child: TweenAnimationBuilder<Color?>(
tween: ColorTween(end: done ? theme.muted : theme.ink),
duration: const Duration(milliseconds: 150),
curve: Curves.ease,
builder: (context, color, _) => Text(
label,
style: _text(theme, color: color).copyWith(
decoration: done ? TextDecoration.lineThrough : null,
decorationColor: done ? color : null,
),
),
),
),
],
),
),
),
),
);
}