title: How to create SharedFlow from 2 StateFlow?
body: <p>I have 2 state flows, and I would like to merge thease into 1 state flow. So, until the 2 data change, the viewModel doesn't call a specific function, with which update the shared flow.</p>
  <p>The problem is, when I open a dialog, and navigate back, the shared flow get a new value, probably because of the 2 state flows fire.</p>
  <p>So my question is, can I somehow achive this behavior, or my whole solution is bad?</p>
  <p>ViewModel:</p>
  <pre><code>private val _selectedMachineComponent = MutableStateFlow&lt;MachineComponentView?&gt;(null)
      val selectedMachineComponent = _selectedMachineComponent.asStateFlow()
  
      private val _previousManufacture = MutableStateFlow&lt;PreviousManufactureView?&gt;(null)
      val previousManufacture = _previousManufacture.asStateFlow()
      
      private val _defaultStateOfWorkflowBarcode =
          _previousManufacture.combine(_selectedMachineComponent) { f1, f2 -&gt;
              if (f1?.machineComponentUnderManufacture == true || f1?.selectedMachineId.isNullOrEmpty() || f2?.id.isNullOrEmpty()) {
  
                  return@combine null
              }
  
              val result =
                  stateOfWorkflowRepository.getDefaultStateOfWorkflowBarcodes(
                      f1?.selectedMachineId!!, f2?.id!!
                  )
  
              if (result is Result.Success &amp;&amp; result.data.isNotEmpty()) {
                  return@combine result.data
              }else{
                  val msg = if (result is Result.ApiErrorMsg) result.msg else &quot;Sikertelen betöltés&quot;
  
                  showSimpleOkDialog(OkDialogView(&quot;Figyelem&quot;, msg ?: &quot;&quot;))
              }
  
              return@combine emptyList()
          }
      val defaultStateOfWorkflowBarcode = _defaultStateOfWorkflowBarcode.shareIn(viewModelScope, replay = 1,started = SharingStarted.WhileSubscribed())
  </code></pre>
  <p>Fragment:</p>
  <pre><code>        viewLifecycleOwner.lifecycleScope.launchWhenCreated {
              viewModel.defaultStateOfWorkflowBarcode.collectLatest {
                  it?.let { list-&gt;
                      if(list.size == 1)
                          viewModel.getStateOfWorkflowByBarcode(list.first())
                      else if(list.isNotEmpty())
                          openStateOfWorkflowSelectionDialog()
                  }
              }
          }
  </code></pre>