So I did a stepper in Compose and followed an exam...
# compose
c
So I did a stepper in Compose and followed an example where I had the state in the Composable method, then called a stepper function and passed it the state. Worked in 03, does not compile in 04, tells me I cannot mutate a val.
Copy code
@Composable
fun MeasureQuestionView() {
    val typography = (MaterialTheme.typography())

    val rangeOfValues = 115..125
    val currentValue = state {rangeOfValues.first}

    Card(shape = RoundedCornerShape(8.dp)) {
        Column(modifier = Spacing(16.dp)) {
            Text("What was your blood sugar reading?", style = typography.h6)
            numberStepper(currentValue, rangeOfValues, "mg/dL")
        }
    }

}

@Composable
fun numberStepper(currentValue: State<Int>, range: IntRange, units: String) {
    val typography = (MaterialTheme.typography())

    Container(height = 75.dp) {
        Row(Spacing(20.dp)) {
            Button(text = "-", onClick = {
                if (currentValue.value > range.first) {
                    currentValue.value -= 1
                }
            })
            Spacer(LayoutWidth(10.dp))
            Text(currentValue.value.toString(), style = typography.h5)
            Spacer(LayoutWidth(10.dp))
            Button(text = "+", onClick = {
                if (currentValue.value < range.last) currentValue.value += 1
            })
            Spacer(LayoutWidth(10.dp))
            Align(Alignment.CenterLeft){
                Text(units)
            }
        }
    }

}
a
The old
State<T>
has been split into
State<T>
and
MutableState<T>
to match the usual kotlin collection interfaces
looks like you now want
MutableState<T>
in your stepper function parameter list
(since
State<T>.value
is indeed now a
val
)
c
strange that ever worked? ok thanks @Adam Powell! compiles now…
a
there was only one interface with
var
in -dev03 🙂
the
state {}
factory returns
MutableState
so if you were relying on inference and refactored, that would do it
👍🏻 1