Question on Flow

Here is my use case:

I have a main flow which is a list of Note, that i’m getting from a ROOM function.

kt @OptIn(ExperimentalCoroutinesApi::class) private val notesWithoutFiltering = currentNoteFolderRelativePath.flatMapLatest { dao.allNoteInPathRecursively(it) }.stateIn( CoroutineScope(Dispatchers.IO), SharingStarted.WhileSubscribed(5000), emptyList() )

In the ui, the user is able to select some notes, so i have a second flow, which is basically just a list of note ID. private val _selectedNotes: MutableStateFlow<List<String>> = MutableStateFlow(emptyList()) val selectedNotes: StateFlow<List<String>> get() = _selectedNotes.asStateFlow()

My problem is that some notes could be removed, so the selectedNotes flow must be updated accordingly.

How can i resolve this issue?

Edit: I guess the question could be, how to update a flow which is sourced by the user, with the state of some repository

submitted by /u/wiiznokes
[link] [comments]