Skip to main content

Toast

A Shadcn toast: a short notification in a corner of the screen that disappears after duration.

Only one toast is visible at a time: showing another one replaces it. For notifications that stack, use Sonner.

Open it with Page.show_dialog, like SnackBar. on_dismiss is called when it disappears, whether it timed out, was closed by the user or was replaced.

Example:

page.show_dialog(
shad.Toast(
title="Scheduled: Catch up",
description="Friday, February 10, 2023 at 5:57 PM",
)
)
Toast
Toast

Inherits: DialogControl

Properties

  • action - A control shown next to the text, usually a small Button such as "Undo".
  • description - The text shown below title.
  • duration - How long the toast stays visible.
  • title - The title of this toast.
  • variant - The visual variant of this toast.

Example​

Shadcn Toast​

play_arrowTry Online
import flet_shadcn_ui as shad

import flet as ft


def main(page: ft.Page):
page.title = "Shadcn Toast"

def undo(e: ft.Event[shad.Button]):
page.pop_dialog()
# pop_dialog() sends its own update, so the page is not auto-updated
# after this handler; send the status change explicitly.
status.value = "Undone"
status.update()

def show_toast(e: ft.Event[shad.Button]):
page.show_dialog(
shad.Toast(
title="Scheduled: Catch up",
description="Friday, February 10, 2023 at 5:57 PM",
action=shad.Button(
"Undo", variant=shad.ButtonVariant.OUTLINE, on_click=undo
),
)
)

def show_error(e: ft.Event[shad.Button]):
page.show_dialog(
shad.Toast(
variant=shad.ToastVariant.DESTRUCTIVE,
title="Uh oh! Something went wrong.",
description="There was a problem with your request.",
action=shad.Button(
"Try again",
variant=shad.ButtonVariant.DESTRUCTIVE,
on_click=lambda e: page.pop_dialog(),
),
)
)

status = ft.Text("Show a toast")

page.add(
ft.SafeArea(
content=ft.Column(
spacing=16,
controls=[
ft.Row(
controls=[
shad.Button(
"Show toast",
variant=shad.ButtonVariant.OUTLINE,
on_click=show_toast,
),
shad.Button(
"Show error",
variant=shad.ButtonVariant.OUTLINE,
on_click=show_error,
),
]
),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
toast
Showing a toast, then an error toast

Properties​

actionclass-attributeinstance-attribute​

action: Control | None = None

A control shown next to the text, usually a small Button such as "Undo".

descriptionclass-attributeinstance-attribute​

description: StrOrControl | None = None

The text shown below title.

durationclass-attributeinstance-attribute​

duration: DurationValue = field(
    default_factory=lambda: Duration(seconds=5)
)

How long the toast stays visible.

titleclass-attributeinstance-attribute​

title: StrOrControl | None = None

The title of this toast.

variantclass-attributeinstance-attribute​

The visual variant of this toast.