Segment Controls Jetpack Compose

Viewed 728

I have tried to make segment Controls but it is not working. I have taken a mutableStateof int as 0 and I'm changing value 0 to 1 onClick but its not working

@Composable
fun SegementControls(){
    var index = remember{ mutableStateOf(0) }
    Row(modifier = Modifier.fillMaxWidth().padding(42.dp).height(30.dp)) {
        Box(modifier = Modifier.width(80.dp).height(30.dp).background(
           color = if (index.value == 0) Color.LightGray else Color.Transparent
            ).clickable { index.value == 0 }){
            Text("Sign In")
        }
        Box(modifier = Modifier.width(80.dp).height(30.dp).background(
                color = if (index.value == 1) Color.LightGray else Color.Transparent
            ).clickable { index.value == 1 }){
            Text("Sign Up")
        }
    }
}

Updated answer here
https://github.com/abhishekumar-dev/SegmentControls/blob/main/SegmentControls.kt

1 Answers

In the clickable modifier you have to assign the value:

Replace

.clickable { index.value == 0 }

with

.clickable { index.value = 0 }
Related