Type 'State<List<User>?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate Type 'State<List<User>?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate android android

Type 'State<List<User>?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate


If you get a compiler error that observeAsState or getValue are not defined make sure you have the following imports:

import androidx.compose.runtime.getValueimport androidx.compose.runtime.livedata.observeAsState

This information is from Step #4 in the "Using State in Jetpack Compose" codelab.


To fix the error add the following imports:

// for a 'val' variableimport androidx.compose.runtime.getValue// for a `var` variable also addimport androidx.compose.runtime.setValue// or justimport androidx.compose.runtime.*

To use a variable as a property delegate you should provide getValue operator function for read-only val variables and getValue and setValue functions for var variables.

To read more about how property delegates and state are combined in jetpack compose see Use remember to create internal state in a composable documentation section. There's also an explanation in Thinking in Compose video.


I think type of items must be nullable since you observing LiveData:

val items: List<User>? by userViewModel.fetchUserList.observeAsState()