Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Last active March 29, 2021 17:29
Show Gist options
  • Select an option

  • Save igorescodro/7d1d26a4fdbd593f37173d082376f67f to your computer and use it in GitHub Desktop.

Select an option

Save igorescodro/7d1d26a4fdbd593f37173d082376f67f to your computer and use it in GitHub Desktop.
@Composable
fun HomeList(taskViewModel: ListViewModel = viewModel()) {
Scaffold {
val list by remember(taskViewModel) {
taskViewModel.taskList
}.collectAsState()
LazyColumn {
items(
items = list,
itemContent = { task ->
ListItem(
task = task,
onCheckedChange = taskViewModel::onCheckedChange
)
}
)
}
}
}
@Composable
private fun ListItem(task: Task, onCheckedChange: (Task) -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
.height(64.dp)
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Checkbox(checked = task.isCompleted, onCheckedChange = { onCheckedChange(task) })
Spacer(Modifier.width(8.dp))
Text(text = task.title)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment