Skip to content
Talk to an engineerRequest access

Citation

Numbered source chips, as in RAG answers.

A sentence with two numbered citation chips, 1 and 2

[1], [2] … in the text render as chips. With a [1]: url line — hidden from the output — a tap opens that URL through onLinkTap. Set onSourceTagTap to handle every tap yourself; it wins when set.

GptMarkdown(reply, onSourceTagTap: (content) => showSource(content))

The chip drawn for a [1] citation, common in RAG answers.

styleSheet: const GptMarkdownStyleSheet(
sourceTag: SourceTagStyle(
size: 18,
backgroundColor: Color(0xFFE8DEF8),
shape: BoxShape.rectangle,
textStyle: TextStyle(fontSize: 11, fontWeight: FontWeight.w600),
),
),
GptMarkdown(text, onSourceTagTap: (content) => showSource(content))

How a [1] citation chip is drawn.

Set it as GptMarkdownStyleSheet(sourceTag: SourceTagStyle(…)) on the widget, or in GptMarkdownThemeData for the whole app. Every field is optional; an unset one falls back to the theme, then to the default.

Field Type Description
backgroundColor Color? Chip fill. Defaults to ColorScheme.onInverseSurface.
textStyle TextStyle? Number style. Defaults to the surrounding style.
size double? Chip diameter. Defaults to 20.
shape BoxShape? Chip shape. Defaults to a circle.
padding EdgeInsetsGeometry? Space around the chip. Defaults to 2.
Member Type Description
merge(SourceTagStyle? other) SourceTagStyle This style, with any unset field taken from other, field by field.
resolve(ColorScheme scheme) SourceTagStyle This style with every remaining default filled in.
copyWith({…}) SourceTagStyle A copy with the given fields replaced.
static lerp(SourceTagStyle? a, SourceTagStyle? b, double t) SourceTagStyle? Linearly interpolates between two styles.

Builds the span for a [1] citation chip, replacing the default chip.

Wins over sourceTagBuilder when both are set.

typedef InlineSourceTagBuilder = InlineSpan Function(
SourceTagBuildDetails details,
);

Called with the tag content when a [1] citation chip is tapped.

void Function(String content)? onSourceTagTap

Builds a widget for a [1] citation chip.

Used only when inlineSourceTagBuilder is null. The result is wrapped in a WidgetSpan, and it is handed an empty TextStyle rather than the resolved one — both kept so 1.2.x code behaves unchanged.

typedef SourceTagBuilder = Widget Function(
BuildContext context,
String content,
TextStyle textStyle,
);

What the source-tag builder is told about one [1] citation chip.

Member Type Description
context BuildContext The element this construct is being built in.
config GptMarkdownConfig The configuration in force at this point in the document.
style TextStyle The text style in effect for this construct, fully resolved.
id String The tag’s contents — 1 for [1].
url String? The URL the document defines for this tag with a [1]: https://… reference definition, or null.
sourceTagStyle SourceTagStyle The resolved SourceTagStyle — fill, text style, size, shape and padding, with theme and defaults already folded in.
onTap VoidCallback? Invokes GptMarkdownConfig.onSourceTagTap with id. Without that handler, a tag with a url invokes GptMarkdownConfig.onLinkTap with the URL and id instead. Null when neither applies.
defaultSpan() InlineSpan The chip the package would have built, as a placeholder span.
asWidgetSpan(…) InlineSpan chip in a placeholder aligned and padded exactly the way the default chip is — centred on the line box, with SourceTagStyle.padding around it — and wired to onTap.
config: more

Read GptMarkdownConfig.scope from it to tell a link in a table cell from one in ordinary content, and GptMarkdownConfig.textDirection or GptMarkdownConfig.textScaler when a widget of your own needs them. TableBuilder and OrderedListBuilder already take a whole config for the same reason.

style: more

A builder never has to guess a default: this is what the construct would have been drawn with, its own style already applied over the surrounding one.

defaultSpan: more

Still a WidgetSpan: the default chip is a sized, filled circle with the number scaled to fit, and there is no text-only equivalent of that. Return this when you only want to wrap or decorate the stock chip.

asWidgetSpan: more

This is the realistic migration for a custom citation chip: it reproduces the wrapping sourceTagSpan applies, which a hand-written WidgetSpan does not.