Leave a rating/review
In this episode, you’ll be setting up the Jetpack Compose navigation library to handle navigation with your app.
To start, you’ll need to add the Jetpack Compose navigation library to your project.
Add the following dependency to your app-level build.gradle file:
implementation "androidx.navigation:navigation-compose:2.5.3"
Do a gradle sync to download the dependency to your project.
Next, you’ll create a sealed class to represent the screens in your app. This class will be used to define the navigation graph for your app.
Create a new package named navigation and add a new file named Screens.kt to it.
Add the following code to the file:
sealed class Screens(val route: String) {
object TaskListScreen : Screens("taskList")
object TaskDetailScreen : Screens("taskDetail")
}
In the code above, you’re defining two screens in your app: TaskListScreen and TaskDetailScreen. Each screen has a route property that represents the route to the screen. The route is used to define the navigation graph for your app.
Your setup is ready! In the next episode, you’ll define the navigation graph for your app.