buildLink method

Widget buildLink(
  1. BuildContext context,
  2. InlineSpan text,
  3. String url,
  4. TextStyle style,
)

Builds a custom inline link widget with hover preview for better user experience.

This method creates a HoverCard-wrapped Text span for Markdown links, blending the link color with the foreground for subtle emphasis. On hover, it displays a SurfaceCard with the link text and URL, using Basic layout for structured preview. Inputs include the link text span, URL, and base style; outputs a selectable, underlined text widget. Enhances accessibility in Section or SliverScreen contexts by providing visual feedback without full navigation.

Implementation

Widget buildLink(
  BuildContext context,
  InlineSpan text,
  String url,
  TextStyle style,
) =>
    HoverCard(
        child: Text(
          text.toPlainText(),
          style: TextStyle(
              color: Theme.of(context)
                  .colorScheme
                  .primary
                  .mix(Theme.of(context).colorScheme.foreground, 50),
              decoration: TextDecoration.underline),
        ),
        hoverBuilder: (context) => SurfaceCard(
                child: Basic(
              leadingAlignment: Alignment.center,
              leading: Icon(Icons.globe),
              title: Text(text.toPlainText()),
              subtitle: Text(url),
            )));