Skip to main content

Alert

An inline notification banner used to convey contextual feedback.

When to use it

Use Alert to surface a contextual message inline in a layout — for example, a form validation summary, a status banner, or a maintenance notice. Supply title and/or children for message content. An optional action (e.g. a Button) sits below the body. Provide onDismiss to show a close button.

Import

import 'package:catalyst_ui/catalyst_ui.dart';

Usage

Alert(
tone: AlertTone.warning,
icon: const Icon(Icons.warning_amber),
title: const Text('Action required'),
children: const [Text('Your subscription is about to expire.')],
onDismiss: _handleDismiss,
dismissIcon: Icons.close,
)

Parameters

ParameterTypeDefaultDescription
toneAlertToneAlertTone.infoThe semantic colour and icon of the alert.
titleWidget?nullAn optional bold title rendered above children.
childrenList<Widget>?nullOptional body content below title.
actionWidget?nullAn optional action widget (e.g. a button) below the body.
iconWidget?nullAn optional icon to display at the start of the alert.
onDismissVoidCallback?nullWhen provided, shows a dismiss button in the top-right corner.
dismissIconIconData?nullIcon to display on the dismiss button. Must be provided when onDismiss is provided.

An assertion enforces that dismissIcon is non-null whenever onDismiss is provided.

Tones

AlertTone presets:

  • AlertTone.info — blue tint; general informational message.
  • AlertTone.success — green tint; positive or completed-action message.
  • AlertTone.warning — amber tint; cautionary message.
  • AlertTone.danger — red tint; error or destructive-action message.

Each tone resolves to an AlertToneStyle with a backgroundColor (tinted banner background) and accentColor (icon and border-tint colour). Define your own by subclassing AlertTone and implementing resolve:

class MaintenanceTone extends AlertTone {
const MaintenanceTone();


AlertToneStyle resolve(ColorScheme cs) => AlertToneStyle(
backgroundColor: cs.warningSoft,
accentColor: cs.warning,
);
}

See Variants & Tones for the full pattern.