0

I have some troubles with the next function:

@Composable
fun AssessmentScreen(
    onClose: (String, String) -> Unit,
    relatedSubSkillIdsJson: String,
    uiState: AssessmentUiState,
    onSelectedOption: (String) -> Unit,
    onShowAnswerFeedback: (Boolean) -> Unit,
    onNextQuestion: () -> Unit,
    onCloseAssessment: () -> Unit,
    navigateToAndPop: (Pair<String, String>) -> Unit,
    goBack: () -> Unit,
    assessmentType: String,
) {
    val context = LocalContext.current
    val activity = context.findActivity()
    val navigationBarHeightDp = activity?.getNavigationBarHeightInDp() ?: 0.dp
    val blur =
        if (uiState.isLoading) dimensionResource(dimen.default_screen_blur) else 0.dp
    val currentArtiIndex = remember { mutableStateOf(0) }
    if (uiState.questions.isNotEmpty()) {
        LazyColumn(
            Modifier
                .fillMaxSize()
                .padding(
                    top = dimensionResource(dimen.default_screen_padding),
                    start = dimensionResource(dimen.default_screen_padding),
                    end = dimensionResource(dimen.default_screen_padding)
                )
                .blur(blur)
        ) {
            item {
                CloseAssessment(
                    relatedSubSkillIdsJson = relatedSubSkillIdsJson,
                    uiState = uiState,
                    questionIndex = uiState.currentQuestionIndex,
                    isAnsweredQuestion = uiState.showAnswerFeedback,
                    onCloseAssessment = { onCloseAssessment() },
                    navigateToAndPop = navigateToAndPop,
                    goBack = goBack
                )
                AssessmentTitle(artiImages[currentArtiIndex.value], assessmentType)
                QuestionDotsIndicator(uiState.questionAnswersStatus)
                AssessmentQuestion(
                    thumbnail = uiState.getCurrentQuestionItem().thumbnail,
                    question = uiState.getCurrentQuestionItem().question
                )
                Spacer(modifier = Modifier.height(20.dp))
            }
            val optionsAbcLetterDescription = ('a'..'z').toList()
                if( uiState.assessmentType != "grid"){
                    LazyVerticalGrid(
                        columns = GridCells.Fixed(2)
                    ) {
                        itemsIndexed(uiState.currentAnswerOptions) {index, option ->
                            AnswerOption(
                                selectedOptionId = uiState.selectedAnswerId,
                                showFeedback = uiState.showAnswerFeedback,
                                optionLetter = circularCharIteration(optionsAbcLetterDescription, index),
                                option = option,
                                onSelectedOption = { onSelectedOption(it) }
                            )
                        }
                    }
                }else{
                    itemsIndexed(uiState.currentAnswerOptions) { index, option ->
                    AnswerOption(
                        selectedOptionId = uiState.selectedAnswerId,
                        showFeedback = uiState.showAnswerFeedback,
                        optionLetter = circularCharIteration(optionsAbcLetterDescription, index),
                        option = option,
                        onSelectedOption = { onSelectedOption(it) }
                    )
                }
            }
            item {
                ChallengeBtn(
                    modifier = Modifier
                        .padding(bottom = navigationBarHeightDp + dimensionResource(dimen.default_screen_padding)),
                    uiState = uiState,
                    navigateToAndPop = navigateToAndPop,
                    onShowAnswerFeedback = { onShowAnswerFeedback(it) },
                    onCloseAssessment = { onCloseAssessment() },
                    onNextQuestion = {
                        if (!uiState.isLastQuestion) {
                            currentArtiIndex.value =
                                nextArtiImage(currentArtiIndex.value)
                            onNextQuestion()
                        }
                    } ,
                    relatedSubSkillIdsJson = relatedSubSkillIdsJson,
                )
            }
        }
    }
    ProgressBarComponentComposable(isLoading = uiState.isLoading)
}

my problem here its that LazyVerticalGrid gives me the next message "Composables can only be invoked from the context of a composable context", im not completly sure but i belive that its because the lazy vertical grid its inside a lazy column not sure really. But what can i do to fix it? i mean i really need that lazy column there but i need the lazy grid too

user10625391
  • 177
  • 3
  • 19

0 Answers0