Pankaj’s answer is correct, StateFlow won’t emit the same value twice. As the documentation suggests:
Values in state flow are conflated using
Any.equalscomparison in a similar way todistinctUntilChangedoperator. It is used to conflate incoming updates tovalueinMutableStateFlowand to suppress emission of the values to collectors when new value is equal to the previously emitted one.
Therefore, to resolve this issue you can create a wrapping class and override the equals (and hashCode) method to return false even if the classes are in fact the same:
sealed class VerificationError {
object Resend: VerificationError()
override fun equals(other: Any?): Boolean {
return false
}
override fun hashCode(): Int {
return Random.nextInt()
}
}