Skip to content
Talk to an engineerRequest access

Alert

GitHub-style callouts: note, tip, important, warning and caution.

Three alerts — a blue Note, a green Tip and an amber Warning — each with an icon, a title and a tinted background

A quote whose first line is one of the five markers, alone on its line:

> [!NOTE]
> [!TIP]
> [!IMPORTANT]
> [!WARNING]
> [!CAUTION]

The marker is case-insensitive. Anything else — [!FOO], or text after the marker — stays an ordinary quote.

A quote whose first line is [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION] is drawn as an alert: an icon and title in an accent colour over the body, beside a bar in the same colour, on a faint tint of that colour with rounded corners. The marker is case-insensitive and must be alone on its line; anything else — [!FOO], or text after the marker — stays an ordinary quote.

> [!WARNING]
> Back up your data before upgrading.

color · backgroundColor · icon · iconSize · showIcon · title · titleStyle · titleGap · textStyle · barWidth · borderRadius · padding · margin · note · tip · important · warning · caution

The top-level fields apply to every type. note, tip, important, warning and caution take an AlertStyle that overrides them for that type, field by field:

styleSheet: const GptMarkdownStyleSheet(
alert: AlertStyle(
barWidth: 4,
backgroundColor: Color(0x0A000000),
borderRadius: Radius.circular(8),
warning: AlertStyle(
title: 'Heads up',
icon: Icons.bolt,
color: Colors.deepOrange,
),
tip: AlertStyle(title: '', showIcon: false), // body only
),
),

Unset, each type gets its own accent colour — a lighter one on a dark ColorScheme — its own icon, and an English title (“Note”, “Tip”, “Important”, “Warning”, “Caution”). Set title to translate them. An empty title with showIcon: false hides the title row.

The background defaults to the accent colour at 8% opacity (12% on a dark scheme), so it blends with whatever surface the alert sits on and follows a custom color. backgroundColor: Colors.transparent turns the tint off, and borderRadius: Radius.zero squares the corners.

Replacing the widget. alertBuilder receives AlertBuildDetails: the type, the resolved style, the stock title row and the rendered content. defaultAlert() returns the stock alert and asBlockQuote() the plain quote, marker included:

GptMarkdown(
text,
alertBuilder: (context, details) {
if (details.type == MarkdownAlertType.tip) {
return details.asBlockQuote(); // no alert for tips
}
return Card(
color: details.style.color!.withValues(alpha: 0.08),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [details.title, const SizedBox(height: 4), details.content],
),
),
);
},
)

An app that sets blockQuoteBuilder and no alertBuilder keeps getting alerts through blockQuoteBuilder, as ordinary quotes — the look it built for quotes does not change. Add an alertBuilder to opt in.

How alerts are drawn — quotes that open with a marker such as [!NOTE]:

Set it as GptMarkdownStyleSheet(alert: AlertStyle(…)) 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
color Color? Accent colour of the bar, the icon and the title. Defaults to a colour per type, adjusted for a dark ColorScheme.
backgroundColor Color? Fill behind the alert. Defaults to a faint tint of color — 8% opacity, 12% on a dark ColorScheme — which blends with whatever surface the alert sits on. Colors.transparent turns it off.
icon IconData? Icon before the title. Defaults to one per type.
iconSize double? Size of the icon. Defaults to 1.15 × the title’s font size.
showIcon bool? Whether the icon is drawn. Defaults to true.
title String? Text of the title — “Note”, “Tip”, “Important”, “Warning” or “Caution” by default. An empty string hides the title row.
titleStyle TextStyle? Applied on top of the title’s default: the surrounding text style in the accent color, semi-bold.
titleGap double? Space between the title row and the body. Defaults to 4.
textStyle TextStyle? Applied on top of the surrounding text style for the body. Defaults to no change.
barWidth double? Thickness of the bar down the side. Defaults to 3.
borderRadius Radius? Rounding of the alert’s corners. The bar is clipped to it as well. Defaults to 6; Radius.zero gives square corners.
padding EdgeInsetsGeometry? Space between the edges of the alert and its content, the bar included on the start side. Defaults to 12 at the sides and 8 at the top and bottom.
margin EdgeInsetsGeometry? Space around the whole alert. Defaults to vertical: 4.
note AlertStyle? Overrides for [!NOTE].
tip AlertStyle? Overrides for [!TIP].
important AlertStyle? Overrides for [!IMPORTANT].
warning AlertStyle? Overrides for [!WARNING].
caution AlertStyle? Overrides for [!CAUTION].
Member Type Description
overrideFor(MarkdownAlertType type) AlertStyle? The override for type, or null.
merge(AlertStyle? other) AlertStyle This style, with any unset field taken from other, field by field — the per-type overrides included.
resolve(MarkdownAlertType type, ColorScheme scheme) AlertStyle The style of one type with every remaining default filled in.
copyWith({…}) AlertStyle A copy with the given fields replaced.
static lerp(AlertStyle? a, AlertStyle? b, double t) AlertStyle? Linearly interpolates between two alert styles.
resolve: more

The per-type override wins over the shared fields. The result carries no per-type overrides of its own.

Replaces the whole alert widget — a quote that opens with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION].

Reach for styleSheet’s AlertStyle first — it covers colours, icons, titles and spacing, per type. The builder receives AlertBuildDetails, whose defaultAlert() and asBlockQuote() return the stock alert and the plain quote.

When this is null and blockQuoteBuilder is set, alerts are drawn by blockQuoteBuilder as ordinary quotes, so an app that customised its quotes keeps its look.

typedef AlertBuilder = Widget Function(
BuildContext context,
AlertBuildDetails details,
);

What the alert builder is told about one alert.

Member Type Description
context BuildContext The element this alert is being built in.
config GptMarkdownConfig The configuration in force at this point in the document.
type MarkdownAlertType Which marker opened the alert.
style AlertStyle The AlertStyle for type, fully resolved: accent colour, icon, title and spacing, with the per-type override, theme and defaults folded in.
title Widget The stock title row — icon and title text in the accent colour — or an empty box when the style hides both.
content Widget The rendered body, without the marker line.
defaultAlert() Widget The alert the package would have drawn.
asBlockQuote() Widget This alert drawn as an ordinary quote, marker line included — exactly what the package drew before it knew about alerts, honouring blockQuoteBuilder.

The kind of an alert, from the marker on the first line of a quote:

Value Description
note [!NOTE] — information worth noticing even when skimming.
tip [!TIP] — optional advice for doing something better.
important [!IMPORTANT] — information needed to succeed.
warning [!WARNING] — something that needs attention straight away.
caution [!CAUTION] — the risks or negative outcomes of an action.
Member Type Description
static fromMarker(String line) MarkdownAlertType? The type line marks, or null when it is not exactly one marker.
static fromMarker: more

Case-insensitive, and surrounding whitespace is ignored. Anything else on the line — or an unknown name such as [!FOO] — is not a marker, and the quote stays an ordinary quote.