Your Second Kotlin Android App

Aug 29 2023 · Kotlin 1.8.21, Android 13, Android Studio Flamingo | 2022.2.1

Part 4: Use Jetpack Navigation

28. Challenge: Set Up TaskDetailsScreenContent

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 27. Create a NavHost Next episode: 29. Complete the TaskDetailsScreen Composable

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 28. Challenge: Set Up TaskDetailsScreenContent

You can already see a list of your todos. In this challenge, you’ll create the TaskDetailScreenContent which is very similar to TaskListScreen which you created earlier in the course.

Create a new file inside the views package named TaskDetailScreen.kt. Inside the file, create a new composable named TaskDetailScreenContent that takes in two parameters: a modifier and a list of strings to represent your task todos.

Add a conditional statement that checks if the list of task todos is empty. If the list is empty, display the EmptyView composable that says “No todos for this task yet”. If the list is not empty, display a LazyColumn composable that uses the ListItemView Composable to display the list of todos.

Pause the video and attempt the challenge.

Welcome back! Hope you had fun with the challenge. Here’s a quick demo of what you should have done.

Start by creating a file named TaskDetailScreen.kt inside the views package. Inside the file, create a new composable named TaskDetailScreenContent that takes in two parameters: a modifier and a list of strings to represent your task todos.

@Composable
fun TaskDetailsScreenContent(
    modifier: Modifier,
    taskTodos: List<String>
) {
    
}

Next, inside the TaskDetailScreenContent add:

if (taskTodos.isEmpty()) {
    EmptyView(message = stringResource(id = R.string.text_no_todos))
} else {
}

Create a string resource named text_no_todos with the value No todos for this task yet. In this code, you’re checking if the list of task todos is empty. If the list is empty, display the EmptyView composable that says “No todos for this task yet”.

Next, add the following code inside the else block:

LazyColumn(
    modifier = modifier,
    content = {
        items(taskTodos) {
            ListItemView(
                value = it,
                onClick = { }
            )
        }
    }
)

In the code above, you’re displaying a LazyColumn composable that contains a items composable. The items composable takes in a list of items and a composable function that represents each item. Inside the items composable, display a ListItemView composable. You’re passing an empty lambda to the onClick parameter of the ListItemView composable because you’re not going to implement the functionality.

Congratulations on being able to create the TaskDetailScreenContent composable!