buildFlashcard function

Widget buildFlashcard(
  1. BuildContext context,
  2. OpenUiNode node
)

Flashcard(front, back, hint?): flips between its faces when tapped.

Implementation

Widget buildFlashcard(BuildContext context, OpenUiNode node) {
  Widget face(Object? value, {required bool back, required String slot}) {
    if (value is String) {
      final theme = node.theme;
      final typography = theme.typography;
      final style = back
          ? TextStyle(
              fontSize: theme.fontSizeOf('Flashcard.back', 16),
              height: 1.3,
              fontWeight: typography.medium,
            )
          : TextStyle(
              fontSize: theme.fontSizeOf('Flashcard', 21),
              height: 1.3,
              fontWeight: typography.semibold,
              letterSpacing: -0.4,
            );
      return InlineText(
        (context, links) => inlineSpans(
          value,
          context,
          style: style.copyWith(color: node.theme.ink),
          links: links,
        ),
        textAlign: TextAlign.center,
      );
    }
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: node.render(value, slot: slot),
    );
  }

  final hint = node.props.string('hint');
  return Flashcard(
    front: face(node.props['front'], back: false, slot: 'front'),
    back: face(node.props['back'], back: true, slot: 'back'),
    hint: hint == null || hint.isEmpty
        ? OpenUiLocalizations.of(context).tapToFlip
        : hint,
  );
}