Kotlin MongoDB Realm flow collect cannot pass param to query

36 Views Asked by At

I'm in stuck.

I have Realm database. In viewmodel I receive data as a flow. In Fragment collect it.

Problem is when i want to filter / pass a param to realm query - there is no changes.

Viewmodel code:

class StateAppModel : ViewModel() {

val savedBooks: StateFlow<List<RealmBook>> = repository.allBooksAsFlowable(SearchDiaryFilters(searchDiaryText.value))
        .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

}

Database:

    fun allBooksAsFlowable(searchDiaryFilters: SearchDiaryFilters? = null): Flow<List<RealmBook>> {
            
            return realm.query<RealmBook>().sort("created", Sort.DESCENDING).asFlow().map { it.list }
  }

Fragment:

lifecycleScope.launch {
            viewModel.savedBooks.collect {
             
                booksAdapter.submitData(it)
            }
        }

I dont't understand how to pass filter string, e.g. on EditText text change.

Thanks in advance!

0

There are 0 best solutions below