'MutableStateFlow and Firebase console with jetpackCompose

I don't know why, but my text in MutableStateFlow doesn't change when i'm changing the string in firebase console. Can someone help me and say why ? I'm putting into flow with emit(Resource.success(data)), and in viewModel, i get the info in MutableStateFlow, and then, get the info on view with collectAsState().

It work correctly, but i wanted to test the case where i'm changing a data in firebase console and see if it update in the application, but no..

If i'm doing this wrong, tell me why, and tell me the case where this is normaly working.

Thank you.

HomeViewModel

//val _posts = MutableStateFlow(emptyList<Post>())
//val posts: MutableStateFlow<List<Post>> = _posts
val post = mutableStateListOf<Post>()

fun loadAllPosts() {
    viewModelScope.launch {
        navRepository.getAllPosts().collect { state ->
            when (state) {
                is Resource.Loading -> {
                    loading.value = true
                }
                is Resource.Success -> {
                    post.addAll(state.data)
                    //_posts.value = state.data
                    loading.value = false
                }
                is Resource.Failure -> {
                    Log.e(state.throwable, state.throwable)
                }
            }
        }
    }
}

FirebaseNavSrc

suspend fun getAllPosts() = flow<Resource<List<Post>>>{
    emit(Resource.loading())
    val snapshot = postCollection.orderBy("timeStamp", Query.Direction.DESCENDING).get().await()
    val posts = snapshot.toObjects(Post::class.java)
    emit(Resource.success(posts))
}.catch {
    emit(Resource.failed(it.message.toString()))
}.flowOn(Dispatchers.IO)

NavRepository

suspend fun getAllPosts() = firebase.getAllPosts()

HomeScreen

//val posts by homeViewModel.posts.collectAsState()
val post = homeViewModel.post


LazyColumn(
            state = rememberLazyListState(),
            verticalArrangement = Arrangement.spacedBy(10.dp)
        ) {
            items(post) { post ->
                //val difference = homeViewModel.getDateTime(homeViewModel.getTimestamp())
                val date = homeViewModel.getDateTime(post.timeStamp!!)
                QuestionCard(
                    name = post.postAuthorName!!,
                    date = date!!,
                    image = post.image!!,
                    text = post.postText!!,
                    like = 0,
                    response = 0,
                    topic = post.topic!!
                )
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source