Hey I have a stateflow for pending file uploads in a viewmodel like this:
Copy code
val uploadFlow = MutableStateFlow<List<UploadState>>(emptyList())
And then each these UploadState object has another stateflow inside of it, is it safe if I use collectAsState e.g. in the MainScreen for the uploadFlow and then the corresponding stateflow from the uploadstate in their composable component? Or is that bad?
f
franztesca
04/15/2023, 10:40 PM
Your UI state (List<UploadState>) should be immutable and not contain other mutable state (like a StateFlow). I would suggest combining the UploadState flows in a single StateFlow of immutable UI states, and expose that to the UI layer
j
Jan
04/16/2023, 1:11 PM
Not sure how I'd do that, how do I convert a List of flows (of a state) then to one flow?
So like: Flow<List<Flow<State>>> to Flow<List<State>>
l
Leo Delon
04/17/2023, 8:04 AM
Hello Ian. What’s the necessity of the second flow? If you want to notify the UI you should just change the first state. Just add whatever you’re sending in the second flow to the class you’re setting on the state. It won’t be a list, you’ll just emit a new state instead