I have a structure that act as a database in my app, this is basically a tree:

sealed class Node {

    Note(val name: String)

    Folder(val name: String, val content: MutableList<Node>)
    
}

This is how i currently create my flow:

private val _data = MutableStateFlow(Node.Folder("", mutableListOf()))
val data: Flow<NoteFolder> = _data

I can sucefully emit the fist value with _data.emit(rootFolder), but i’m having truble to update a nested Node.

I would like a function like this:

fun updateNestedNodeName(previousName: String, newName: String) {

    _data.update { data ->
        val note: Node.Note = data.findByName(previousName)
        note.name = newName
        data
    }
}

But this won’t update the UI (I think this is because i’m not changing the pointer of _data so Kotlin thinks the flow hasn’t change).

I feel like i’m missing something here, I’ve never seen anyone have this problem on the internet. Is it good design to use flows here?

Also, I would really like to avoid having to use room.

Thanks