3

I'm adding my notes in "items" but I'm getting this error. I couldn't find the reason, can you help?

@Composable
fun NotesList() {
    val notesList = remember { mutableStateListOf<Note>() }
    LazyColumn {
        items(notesList) {note->
            NoteCard(note.title, note.content,note.color,note.liked)
        }
    }
}

When I hover the cursor over noteList I get the following error.

Type mismatch. Required:Int Found:SnapshotStateList

I was hoping it would work by adding my list to items but it didn't.

1 Answers1

3

Adding this import should fix that:

import androidx.compose.foundation.lazy.items

This is because the fun items(count: Int) function is a member function of LazyListScope but the fun <T> LazyListScope.items(items: List<T>) is an extension function of LazyListScope. Therefore, you don't need any import to use the first one, but you need that import to use the second one. If you (or Android studio) doesn't add the import, the one with count is automatically used and it doesn't work when you pass list instead.

Jan Bína
  • 3,447
  • 14
  • 16