我正在“items”中添加注释,但收到此错误。我找不到原因,你能帮忙吗?
@Composable
fun NotesList() {
val notesList = remember { mutableStateListOf<Note>() }
LazyColumn {
items(notesList) {note->
NoteCard(note.title, note.content,note.color,note.liked)
}
}
}
当我将光标悬停在 noteList 上时,出现以下错误。
类型不匹配。 要求:智力 找到:SnapshotStateList
我希望通过将我的列表添加到项目中可以发挥作用,但事实并非如此。
添加此导入应该可以解决这个问题:
import androidx.compose.foundation.lazy.items
这是因为
fun items(count: Int)
函数是 LazyListScope
的成员函数,但 fun <T> LazyListScope.items(items: List<T>)
是 LazyListScope
的扩展函数。因此,您不需要任何导入即可使用第一个,但需要该导入才能使用第二个。如果您(或 Android studio)没有添加导入,则会自动使用带有 count
的导入,并且当您传递列表时它不起作用。