escodro
03/29/2021, 1:03 PMSnackBar. I have a list of items with Checkbox and when the user clicks, it “completes” the item and removes from the list.
My implementation tries to shown an “Undo Snackbar” when the user performs this action, which brings the item back to the list.
The problem is that the Snackbar disappears in less than one second due to the recompostion when the item disappears from the list.
LazyColumn() {
items(
items = taskList,
itemContent = { task ->
TaskItem(
task = task,
onItemClick = onItemClick,
onCheckedChange = {
onCheckedChange(it)
coroutineScope.launch { snackbarHostState.showSnackbar("Task Completed", "Undo") }
}
)
}
)
}
I tried using LaunchedEffect but AFAIK, this will associate the effect to a state, not the user click, right?
Do you have any idea on how to make the Snackbar keep visible while the screen is recomposing?
Thanks a lot in advance! ❤️Adam Powell
03/29/2021, 1:54 PMcoroutineScope declared in that snippet?escodro
03/29/2021, 2:03 PMScaffold definition and it works now.
For some reason I thought it was “bad” to pass a CoroutineScope as a parameter in a composable function.
Thanks a lot, Adam. 😊Adam Powell
03/29/2021, 2:07 PMonCheckedChanged(it) from the snippet, so that you're not passing the scope down directly, only as part of the changed lambdaescodro
03/29/2021, 2:12 PM