5
@Composable
fun getData() {
        var wordData = arrayListOf<Word>()
        db.get().addOnSuccessListener { documents ->
            for (document in documents) {
                wordData.add(document.toObject(Word::class.java))
            }
        }
        LazyColumn {
            items(wordData) {  word ->
                WordCard(word = word)
            }
        }
    }

I wanted to use Lazy Column to show all of my words data, these are my WordCard codes.

@Composable
fun WordCard(word: Word) {
    Text(text = word.word, color = Color.Black, modifier = Modifier.background(Color.Gray).padding(12.dp))
}
z.g.y
  • 5,512
  • 4
  • 10
  • 36
  • 2
    Besides z.y's answer, I think that this [resource](https://medium.com/firebase-developers/how-to-display-data-from-firestore-using-jetpack-compose-49ee736dc07d), this [resource](https://medium.com/firebase-tips-tricks/how-to-read-data-from-cloud-firestore-using-get-bf03b6ee4953) and this [resource](https://medium.com/firebase-tips-tricks/how-to-make-a-clean-architecture-android-app-using-mvvm-firestore-and-jetpack-compose-abdb5e02a2d8) might help. – Alex Mamo Nov 14 '22 at 13:40

1 Answers1

4

Not sure if this is a firebase issue, but I notice this.

var wordData = arrayListOf<Word>()

You are just adding elements to a standard collection structure, not something that compose can observe state changes for it to update your LazyColumn.

So please change it to this using SnapshotStateList and wrap it to a remember{…} so the list won't re-initialize on succeeding re-compositions

val wordData = remember { mutableStateListOf<Word>() }
z.g.y
  • 5,512
  • 4
  • 10
  • 36