https://kotlinlang.org logo
a

Alan Yin

01/19/2021, 10:31 AM
Modifier in if not working, please see code below
Copy code
val modifier = Modifier
        .preferredWidth(292.dp)
        .preferredHeight(87.dp)
        .clickable(onClick = { selectedItem.value = item })
    if (item == selectedItem.value){
        Timber.i("on item selected ")
        modifier.background(brush = lightHighLightGradient)
    }
    Text(
        modifier = modifier,
        // .padding(start = 35.dp),
        text = stringResource(id = item),
        fontSize = 32.sp,
        textAlign = TextAlign.Center
    )
1
🙌 1
f

fmasa

01/19/2021, 10:33 AM
Modifiers are immutable, so
Modifier.background()
returns new instance, so you either have to make modifier
var
and replace
modifier.background(brush = lightHighLightGradient)
by
modifier = modifier.background(brush = lightHighLightGradient)
, or restructure it in other way.
🙌 1
1
a

Alan Yin

01/19/2021, 11:24 AM
Thank you so much!
2 Views