Initialize A Kotlin MutableStateFlow Without An Initial Value

[Solved] Initialize A Kotlin MutableStateFlow Without An Initial Value | Kotlin - Code Explorer | yomemimo.com
Question : Initialize a kotlin MutableStateFlow without an initial value

Answered by : abdullah-0kvpuik7ilzv

You can't, Mutable stateFlow require an initial value.
One way is to set this value nullable and init it with null.
But it's a trick and there is another way using channel and receive it as flow :
private val _status = Channel<Status>()
val status = statusChannel.receiveAsFlow()

Source : | Last Update : Fri, 03 Jun 22

Answers related to Initialize a kotlin MutableStateFlow without an initial value

Code Explorer Popular Question For Kotlin