image.png
# compose
a
image.png
j
First of all
remember
is a composable function. So, you can only call it from
Composable
functions
a
I am following the android documentation for this, and it does not have any compose on the class. https://developer.android.com/develop/ui/compose/quick-guides/content/validate-input
j
in the documentation remember is not used. it's just mutableStateOf
a
Yes man, i did not notice that. Thanks so much.
👍 1
the error is still there even though I removed it.
Copy code
var email by mutableStateOf("")
j
Hover the mouse over the error and import if anything is suggested.
a
When i hover on the error it shows me this below message "Type 'androidx. compose. runtime. MutableState<kotlin. String>' has no method 'getValue(EmailViewModel, KMutableProperty1<*, *>)', so it cannot serve as a delegate. Type 'androidx. compose. runtime. MutableState<kotlin. String>' has no method 'setValue(EmailViewModel, KMutableProperty1<*, *>, ERROR CLASS: Unresolved name: getValue)', so it cannot serve as a delegate for var (read-write property)."
j
import androidx.compose.runtime.getValue
Add this import
by the this 4 imports need to be added
Copy code
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.derivedStateOf
a
Yup, i added these both and it worked.
Copy code
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
Why it could not imported auto?
j
these are delegations to set and get values when you use
by
👍 1
So, these are the difference of using delegation
Copy code
var email:String by mutableStateOf("")
    val email2: MutableState<String> = mutableStateOf("")

    init{
        email = "hello@gmail.com"
        email2.value = "hello@gmail.com"
    }
a
Its helpful - thanks