Skip to content

Toast

Category: UI

Source: toast.dart

Enums

ToastKind

ValueDescription
success
error

Classes

Toast

Transient corner notification — narrow chip painted directly into the output viewport at top-right by [App._render]. Holds its own visibility

  • dismiss timer.

Why not a DockedPanel: the dock manager always paints horizontal floating panels at full output width, which blanks the entire row behind the chip. The toast is narrow by design (chip width = content + padding) so we paint it directly. Picking content width also means a single paintRect call only touches the chip's own cells and leaves the rest of the top row of transcript visible.

Visual style — charcoal chip (256-colour 236) + dim text (250) with the glyph in yellow (220) for success or red (196) for failure.

Constructor

dart
Toast({
    required this.onRender,
    this.successDuration = const Duration(milliseconds: 1800),
    this.errorDuration = const Duration(milliseconds: 3500),
  })

Properties

PropertyTypeDescription
successDurationDurationConfigurable for tests; production uses the defaults.
errorDurationDuration
visiblebool get
cellWidthint getCell width of the rendered chip, including the 1-cell left/right inner padding around the glyph + message. Use this to size the paintRect so it doesn't blank cells it shouldn't.
visiblebool get
cellWidthint getCell width of the rendered chip, including the 1-cell left/right inner padding around the glyph + message. Use this to size the paintRect so it doesn't blank cells it shouldn't.

Methods

void show(String message, {ToastKind kind = ToastKind.success})

Show [message] with kind-appropriate duration. A second call cancels any in-flight dismiss timer and replaces the message.

void dismiss()

Cancel any in-flight timer and hide immediately. Safe to call when the toast is already hidden (no-op).

String renderLine()

The ANSI-styled chip body. Returns an empty string when the toast isn't visible; callers should if (toast.visible) before painting.

Released under the MIT License.