Hello folks. Is there a way to avoid MutableStateF...
# android
c
Hello folks. Is there a way to avoid MutableStateFlows posting the same value when the screen is rotated like what we have with SingleLiveEvent version of LiveData? I'm using this guy right here:
Copy code
private val _errorStateFlow = MutableStateFlow<State<Error>>(InitialError)
    internal val errorStateFlow: StateFlow<State<Error>>
        get() = _errorStateFlow
Since it is an Error StateFlow, everytime it posts something, i show a SnackBar on the screen but i just want to do this one time for each time the error occurs. Any thoughts on it? Appreciate ya 👍
a
Errors are better modelled as events, rather than state. Because state is always supposed to be re-emitted. This is one way to model events. https://proandroiddev.com/android-singleliveevent-redux-with-kotlin-flow-b755c70bb055
s
Agreed, i would separate my flows for side effect events. Use SharedFlow for toasts / snackbars / one off things
👍 4
c
SharedFlow is a good way to publish events.
👍 3
s
+1 for just using shared flow, it's simple and reliable and just works
o
I would recommend Channel over SharedFlow for events.
c
Nice. Thanks so much guys 👍