Hello All, I'm facing a issue with the StateFlows ...
# compose
d
Hello All, I'm facing a issue with the StateFlows in composable, for some reason the Stateflow is making the composable re-render infinitely even when there is no update to the value. Below is the code for the same
In the ViewModel(questionnaireViewModel)
Copy code
private val selectedMasterDataItem = MutableStateFlow(listOf<DataItem>())
val selectedMasterDataItemList: StateFlow<List<DataItem>> get() = selectedMasterDataItem


fun onCommodityCheckBoxClicked(dataItemId: DataItem) {
    selectedMasterDataItem.value =
        selectedMasterDataItem.value.toMutableList().also { list ->
            if (list.contains(dataItemId)) list.remove(dataItemId) else list.add(dataItemId)
        }
}
In the composable function
Copy code
val checkedItemList = questionnaireViewModel.selectedMasterDataItemList.collectAsState()
val idListForAnswer = ArrayList<String>()

    if (!checkedItemList.value.isNullOrEmpty()) {
        var count: String? = null
        checkedItemList.value.forEach {
            idListForAnswer.add(it.key!!)
        }
        if (idListForAnswer.size > 1) {
            count = idListForAnswer.size.toString().plus(" ").plus(stringResource(id = R.string.COMMODITY_SUFFIX))
            textState.value = count
        } else {
            textState.value = checkedItemList.value.first().name!!
        }
        currentAnswer.multiValueAnswer = idListForAnswer
        MappingUtils.getAnswerForItemId(
            questions.itemId!!,
            null,
            aList = qResponse.answers as List<AnswersItem>,
            idListForAnswer,
            true
        )
    } else {
        val idListForAnswer = ArrayList<String>()
        currentAnswer.multiValueAnswer = idListForAnswer
        MappingUtils.getAnswerForItemId(
            questions.itemId!!,
            null,
            aList = qResponse.answers as List<AnswersItem>,
            idListForAnswer,
            true
        )
    }
the function onCommodityCheckBoxClicked(dataItemId: DataItem) is storing the list of dataItem, which user selects from the list which is shown in a different composable screen
is there a way i can debug this state-flow and check what is causing this to refresh when there is no new value that is being added