> For the complete documentation index, see [llms.txt](https://swift-packages.gitbook.io/materialuikit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swift-packages.gitbook.io/materialuikit/components/snackbar.md).

# Snackbar

### Overview

Snackbars provide quick, unobtrusive messages that can include an action button. Useful for showing brief messages at the bottom of the screen.

The `snackbar` modifier allows you to present a Material Design styled snackbar with a message, optional duration, and action button. You can configure the snackbar to fit your needs by specifying its duration and providing an action for the user.

To use the `snackbar` modifier, apply it to any View with the required parameters.&#x20;

### Modifers

Presents a snackbar with a message and a default display duration of 5 seconds.

```swift
snackbar(isPresented: Binding<Bool>, message: String)
```

Presents a snackbar with a message, a custom duration, and an optional action button.

```swift
snackbar(
    isPresented: Binding<Bool>,
    message: String,
    duration: Double,
    actionButtonKey: String,
    action: (() -> Void)?
)
```

### **Parameters**

<table><thead><tr><th width="237">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>isPresented</code></td><td>A Binding to control the visibility of the snackbar.</td></tr><tr><td><code>message</code></td><td>The message displayed in the snackbar.</td></tr><tr><td><code>duration</code></td><td>The duration (in seconds) for which the snackbar is visible. Defaults to 5s.</td></tr><tr><td><code>actionButtonKey</code></td><td>The title of the action button. If <code>nil</code>, no button is displayed.</td></tr><tr><td><code>action</code></td><td>The closure to execute when the action button is tapped. Defaults to <code>nil</code>.</td></tr></tbody></table>

### **Example**

Displays snackbar with a simple message and a default duration of 5 seconds.

```swift
@State private var showSnackbar = false

var body: some View {
    Container {
        Switch("Show Default Snackbar", isOn: $showSnackbar)
    }
    .snackbar(isPresented: $showSnackbar, message: "This is a snackbar message.")
}
```

<figure><picture><source srcset="/files/k5h55Wa3lM8dfxUFjwKU" media="(prefers-color-scheme: dark)"><img src="/files/yrFrj1tPfWOO3bsdrm5r" alt=""></picture><figcaption></figcaption></figure>

Displays a snackbar with a custom message, a custom duration, and an optional action button.

```swift
@State private var showSnackbarWithButton = false

var body: some View {
    Container {
        Switch("Show Snackbar with Button", isOn: $showSnackbarWithButton)
    }
    .snackbar(
        isPresented: $showSnackbarWithButton,
        message: "Action needed!",
        duration: 10,
        actionButtonKey: "Retry"
    ) {
        Void()
    }
}
```

<figure><picture><source srcset="/files/OYfP8CtQika290HCQvq4" media="(prefers-color-scheme: dark)"><img src="/files/8vJ9fIkvYdFh2Yp3GeRr" alt=""></picture><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://swift-packages.gitbook.io/materialuikit/components/snackbar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
