codeslubber
01/30/2020, 3:59 AM@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)
}
}
}
}
Adam Powell
01/30/2020, 4:04 AMState<T>
has been split into State<T>
and MutableState<T>
to match the usual kotlin collection interfacesAdam Powell
01/30/2020, 4:04 AMMutableState<T>
in your stepper function parameter listAdam Powell
01/30/2020, 4:06 AMState<T>.value
is indeed now a val
)codeslubber
01/30/2020, 4:07 AMAdam Powell
01/30/2020, 4:07 AMvar
in -dev03 🙂Adam Powell
01/30/2020, 4:08 AMstate {}
factory returns MutableState
so if you were relying on inference and refactored, that would do it