我尝试用 jetpack compose 中的 Observer AsState 从 LiveData 获取一个值,但是我得到了一个奇怪的错误
类型‘ State < List? >’没有方法‘ getValue (Nothing? , KProperty < * >)’,因此它不能作为委托
@Composable
fun UserScreen(userViewModel:UserViewModel){
val items: List<User> by userViewModel.fetchUserList.observeAsState()
UserList(userList = items)
}
class UserViewModel: ViewModel() {
private val dataSource = UserDataSource()
val fetchUserList = liveData {
emit(dataSource.dummyUserList)
}
}