https://kotlinlang.org logo
#compose
Title
# compose
g

Guy Bieber

08/25/2020, 12:27 AM
I am using dev17 and the format function isn’t an @Compose function hence this value does not update:
Copy code
val mDataModel = remember {dataModel}                    

                    ui.TextLabelStyled(
                        text = "%.1f".format(mDataModel.value),
                        color = mDataModel.targetColor,
                        fontSize = valueFontSize,
                        modifier = Modifier
                    )
Is there a workaround?
g

gildor

08/25/2020, 3:25 AM
how do you update
dataModel
?
g

Guy Bieber

08/25/2020, 4:56 PM
I change dataModel.value. Here is the dataModel definition:
Copy code
class BasicStatusDataModel<T> (
    var state: ControlState = ControlState(), // already mutable
    targetColor : Color = nikolaColors.color3, // wrapped mutable
    val transitionTimeoutMs : Long = 2*1000,
    name : String = "", // wrapped mutable
    value : T, // wrapped mutable
    unit : String = "", // wrapped mutable
    showActive : Boolean = false // wrapped mutable
) {

    var targetColor by mutableStateOf(targetColor)
    var name  by mutableStateOf(name)
    var value by mutableStateOf(value)
    var unit  by mutableStateOf(unit)
    var showActive  by mutableStateOf(showActive)
Does the whole dataModel need to be wrapped as a mutable.
I really miss @Model. This latest change has been a bit of a nightmare.
g

gildor

08/25/2020, 11:52 PM
And how do you update
value
? Because it says that it mutable
g

Guy Bieber

08/26/2020, 4:46 PM
dataModel.value = newvalue
2 Views