Question:
I have a class that has composable functions which is private as well as methods i cant get a value from my view model when accessing it from a normal class method but inside a composable i can access it what can i do?Updated
Here is my viewmodel
Answer:
I used the same code as in your ViewModel, but I fixed the compiler error forLiveData<Int>
to LiveData<String>
. I also changed the empty starting state string to "initial value"
for this example.Example
class code I fixed another compiler warning where the name of the function you call does not match the actual function name. So I changed state.getSomething()
to state.getSomeValue()
and I added a Log.d
call to log the result.fun getSomeValue()
.Then I made a Composable function/component where I call both functions from your class.
If you have better answer, please add a comment about this, thank you!