Hey everyone, I am using the new `ContextualFlowRo...
# compose
v
Hey everyone, I am using the new
ContextualFlowRow
and i am facing a weird bug, i'm sure i followed the code same as whats there in the docs Code and Stack Trace in thread 🧵
🧵 1
z
Please keep large code snippets to the thread to keep the main channel readable, thanks
v
Copy code
@Composable
 fun <T> ChipRow(
     chips: List<T>,
     maxLines: Int,
     lineStepUpCount: Int = 4,
     modifier: Modifier = Modifier,
     horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(8.dp),
     verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(0.dp),
     expandOrCollapseIndicator: @Composable (Int, () -> Unit) -> Unit = { rem, onClick ->
         AssistChip(
             onClick = onClick,
             label = {
                 val text = if (rem == 0) "Show Less" else "+ $rem"
                 Text(text = text)
             },
             colors = AssistChipDefaults.assistChipColors().copy(
                 labelColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.6f)
             ),
             border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary.copy(alpha = 0.6f))
         )
     },
     chip: @Composable (T) -> Unit,
 ) {
     var maxLineCount by remember { mutableStateOf(maxLines) }
     val expandOrCollapseIndicator: @Composable ContextualFlowRowOverflowScope.() -> Unit = {
         val itemsLeft = totalItemCount - shownItemCount
         expandOrCollapseIndicator(itemsLeft) {
             if (itemsLeft == 0) maxLineCount = maxLines
             else maxLineCount += lineStepUpCount
         }
     }
     ContextualFlowRow(
         itemCount = chips.size,
         modifier = modifier.animateContentSize(),
         horizontalArrangement = horizontalArrangement,
         verticalArrangement = verticalArrangement,
         maxLines = maxLineCount,
         overflow = ContextualFlowRowOverflow.expandOrCollapseIndicator(
             minRowsToShowCollapse = maxLines + 1,
             collapseIndicator = expandOrCollapseIndicator,
             expandIndicator = expandOrCollapseIndicator,
         )
     ) {
         chip(chips[it])
     }
 }
Now im getting this error and app crashes
Copy code
java.lang.IllegalArgumentException: Key "true30" was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item 
at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:453)
at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$Scope.subcompose(SubcomposeLayout.kt:895)
at androidx.compose.foundation.layout.FlowMeasureLazyPolicy$measure$2.invoke(ContextualFlowLayout.kt:463)
z
If you’re just copying the docs code though then it might be a real bug, either in the docs or the impl. Please file a bug in the tracker, link is in the channel topic
c
Is there anything else known about this bug? The same thing is happening to me with items inside a LazyColumn @Zach Klippenstein (he/him) [MOD]
Untitled
Screenshot 2025-03-04 at 10.02.04.png
Copy code
@Deprecated("ContextualFlowLayouts are no longer maintained")
@Composable
@ExperimentalLayoutApi
fun ContextualFlowRow(
ok, hahaha