You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want use a custom data class within a ViewModel but the view is not updated automatically.
Can someone tell me what's wrong?
The attached example show's what I try to do.
When I change a value inside DataContainer (prop1 or prop2) the UI is not updated.
I want prop1 and prop2 to behave like prop3. (prop3 works)
I already tried many different ways to automatic update the ui but nothing works.
Shared Code:
import dev.icerock.moko.mvvm.flow.cMutableStateFlow
import dev.icerock.moko.mvvm.viewmodel.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
data class DataContainer(
var prop1 : String,
var prop2 : String,
)
class ExampleViewModel: ViewModel() {
val dataStateFlow = MutableStateFlow(
DataContainer(prop1 = "1", prop2 = "2")
).cMutableStateFlow()
val prop3 = MutableStateFlow("3")
.cMutableStateFlow()
fun extendProp1() {
dataStateFlow.value.prop1 += "_1"
}
fun extendProp2() {
dataStateFlow.value.prop2 += "_2"
}
fun extendProp3() {
prop3.value += "_3"
}
}
I want use a custom data class within a ViewModel but the view is not updated automatically.
Can someone tell me what's wrong?
The attached example show's what I try to do.
When I change a value inside DataContainer (prop1 or prop2) the UI is not updated.
I want prop1 and prop2 to behave like prop3. (prop3 works)
I already tried many different ways to automatic update the ui but nothing works.
Shared Code:
SwiftUI Code:
The text was updated successfully, but these errors were encountered: