Is it fine to put StateFlow in the data class?

Hello, I just thought - is it fine to put StateFlow / MutableStateFlow in your data class or you need to proxy it in the ViewModel while using with Compose?

In general, I would avoid mutable data in a data class. I view data classes as immutable objects, though technically it is not enforced. But in this case, it would not be good for the semantics of the generated equals and hash code functions.

2 Likes

Yeah, the state vars are in the class section, so there is no need to care about equality. But maybe it will be when you need to parcelize and save it.