Could someone please hint on how to build a list t...
# compose-desktop
t
Could someone please hint on how to build a list that allows multiple selection of items? Here is what I have so far:
Copy code
@Composable
fun ThirdRow(currentPos: Int, checksums: List<String>) {
    val items = if (checksums.isNotEmpty())
        df.getFiles(checksums[currentPos]) else emptyList()
    LazyColumnFor(items,
            modifier = Modifier.fillMaxSize().padding(8.dp),
            itemContent = { item ->
                ListItem(text = { Text(item.parent) },
                        secondaryText = { Text(item.name) })
            })
}
j
Copy code
@Composable
fun ThirdRow(currentPos: Int, checksums: List<String>, selected: Set<String>, onSelectionToggled: (String)->Unit) {
    val items = if (checksums.isNotEmpty())
        df.getFiles(checksums[currentPos]) else emptyList()
    LazyColumnFor(items,
            modifier = Modifier.fillMaxSize().padding(8.dp),
            itemContent = { item ->
                if(selected.contains(item.checksum)) { ... }
                else { ... }
                // TODO: Add a click handler that will invoke onSelectionToggled(item.checksum) when selection is toggled.
                ListItem(text = { Text(item.parent) },
                        secondaryText = { Text(item.name) })
            })
}
👍 1
d
Modifier.toggleable(...)
👍 1
What do you mean by more built in?
Modifier.toggleable(...)
is built in.
👍 1
j
I think he is looking for a built-in multi-select column widget. Under this assumption, no, I don't think there is anything more built-in, but the solution here is just a few lines of code. Often, generalized solutions to problems like this end up adding more cognitive overhead to learn+use than to just re-implementing when needed, but if you create a generalization of this that you think would be useful to other people, feel free to share on github or maven.
👍 2