buildLink function

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

Implementation

Widget buildLink(BuildContext context, OpenUiNode node) {
  final text = node.props.string('text') ?? '';
  final uri = webUri(node.props['url']);
  if (uri == null) return Text(text);
  final base = DefaultTextStyle.of(context).style;
  final resting = node.theme.borderStrong;
  return Semantics(
    link: true,
    child: Press(
      radius: 0,
      onTap: (_) => node.services.openUrl(uri),
      builder: (hovered, pressed) => Text.rich(
        TextSpan(
          children: [
            TextSpan(text: text.isEmpty ? uri.host : text),
            WidgetSpan(
              alignment: PlaceholderAlignment.middle,
              child: Padding(
                padding: const EdgeInsetsDirectional.only(start: 2),
                child: Glyph(
                  'arrow-up-right',
                  size: (base.fontSize ?? 14) * 0.85,
                  color: base.color,
                  strokeWidth: 2,
                ),
              ),
            ),
          ],
        ),
        style: base.copyWith(
          decoration: TextDecoration.underline,
          decorationColor: hovered ? base.color : resting,
        ),
      ),
    ),
  );
}