I want to add a separator/Divider in a column afte...
# compose
k
I want to add a separator/Divider in a column after each item except last item, I don’t want to add more logics to check which one will be a last item. Any suggestions here?? For example i have 10 items inside my column but each can be added based a boolean condition, so anything can be the last item.
Compose is not inheritance based, so i couldn’t extend column and try a custom variant, and all the impl are internal
n
if it's a lazyColumn you can use itemsIndexed instead of items and wrap your divider in an if, something like this
Copy code
val myList = listOf()
itemsIndexed(items = myList) { index, item ->
    // item composable
    if (index < myList.lastIndex) {
        Divider()
    }
}
is it ok for your use case?
k
if i had list yes this is possible, Am thinking, because for my usecase i don’t want a expensive lazy column, just column is enough
s
Put your composables in a list and iterate over them with the index 🤷‍♂️
n
Yup, I agree with @Stylianos Gakis, you can iterate your items with a forEachIndexed inside a regular column and use the same logic of my previous example
👍 1
108 Views