alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

How can I assign a private mutableStateOf to a State variable Jetpack in Android ?

How can I assign a private mutableStateOf to a State variable Jetpack in Android ?
 // _isRecording is a Boolean
private var _isRecording by mutableStateOf(false)
// _isRecording is a State<Boolean>
private var _isRecording = mutableStateOf(false) 

This is why you're getting this error.

You should expose like this:

 class SoundViewModel @Inject constructor(): ViewModel() {

    private var _isRecording = mutableStateOf(false)
    val isRecording: State<Boolean> = _isRecording
} 

and consume like this:

 @Composable
fun YourComposable(soundViewModel: SoundViewModel) {
    val isRecording by soundViewModel.isRecording

244 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online