From the course: Android Compose with Kotlin
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Display snackbar messages - Kotlin Tutorial
From the course: Android Compose with Kotlin
Display snackbar messages
- [Instructor] I've updated our app so that we can favorite and unfavorite sessions. However, we don't receive any feedback when that happens. We're going to add a Snackbar whenever the user saves or removes the sessions. When you're working with Android views, it's pretty straightforward. Here now utilities class, we have a call to snackbar.make. We provide a few options and then finally we'll call show. However, when working with Compose, it takes a bit more thinking. To get started, we'll move over to our primary app composable and we're going to create a new variable. Like many things in Jetpack Compose, we must use Remember, and it's going to be for the SnackbarHostState. So I'll come here for underneath where we have our current destination, and I'll create this new variable, which I'm going to name SnackbarHostState and I'll set this equal to remember and we'll create a new SnackbarHostState. Now what does this do? The SnackbarHostState controls the queue of Snackbars so that…
Contents
-
-
-
-
-
-
-
-
(Locked)
Explore lazy layouts in Compose5m 47s
-
(Locked)
Add a LazyGrid to a composable screen6m 24s
-
(Locked)
Handle lazy layout item click events4m 11s
-
(Locked)
Handle loading and empty states7m 53s
-
(Locked)
Display snackbar messages6m 4s
-
(Locked)
Pass data in a ViewModel3m 54s
-
(Locked)
Challenge: Adding some polish1m 36s
-
(Locked)
Solution: Adding some polish2m 9s
-
(Locked)
-
-
-