produceAndCollectAsRetainedState
Produces and collects values from a Flow provided by the producer lambda and represents its latest value via retained State. Every time there would be a new value posted into the Flow, the returned State will be updated causing recomposition of every State.value usage.
This function safely produces and collects a Flow by using a single retained state with unified inputs. The Flow is produced within the retained state's producer block, ensuring proper scoping and preventing memory leaks by re-initializing retained Flow instances across configuration changes.
Parameters
A set of inputs such that, when any of them have changed, will cause the state to reset and producer to be rerun
the initial value for the state
CoroutineContext to use for collecting.
a suspend lambda that provides the Flow to collect from