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

前端 未结 4 1179
我寻月下人不归
我寻月下人不归 2021-02-13 02:53

I\'m trying to get a value from LiveData with observeAsState in jetpack compose, but I get a weird error

Type \'State\' has no method \'getValue

4条回答
  •  清歌不尽
    2021-02-13 03:18

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

    import androidx.compose.runtime.getValue

    import androidx.compose.runtime.livedata.observeAsState

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

提交回复
热议问题