this below is my code which is fetching data from firestore and i want some text or sentence to be bold or italic or underlined along with if there is math formula written in text in firestore i would like it to be also rendered in the app UI or if any images present also to be rendered.
I tried but could include all three of them to render and i were only able to do text styling and not the math formula rendering.
@Composable
fun QuestionCard(questionText: String) {
Card(
modifier = Modifier
.padding(8.dp)
.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = Color.Transparent)
) {
Text(
text = questionText,
style = MaterialTheme.typography.headlineSmall,
fontWeight = Bold,
fontSize = 18.sp,
modifier = Modifier.padding(16.dp)
)
}
}
// Option card with feedback colors
@Composable
fun OptionCard(
optionText: String,
isSelected: Boolean,
isCorrect: Boolean,
showCorrectAnswer: Boolean,
disabled: Boolean,
onSelect: () -> Unit
) {
val backgroundColor = when {
isSelected && isCorrect -> AppColors.OptionGreen
isSelected && !isCorrect -> AppColors.OptionRed
showCorrectAnswer && isCorrect -> AppColors.OptionGreen
else -> Color.White
}
val radioColors = RadioButtonDefaults.colors(disabledSelectedColor = MaterialTheme.colorScheme.primary)
Card(
modifier = Modifier
.padding(4.dp)
.fillMaxWidth()
.clickable(enabled = !disabled) { onSelect() },
colors = CardDefaults.cardColors(containerColor = backgroundColor),
elevation = CardDefaults.cardElevation(5.dp)
) {
Box(
modifier = Modifier
.padding(12.dp)
.fillMaxWidth(),
contentAlignment = Alignment.CenterStart // Align content to the start
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
RadioButton(
selected = isSelected,
onClick = onSelect,
enabled = !disabled,
colors = radioColors,
modifier = Modifier.padding(start = if (isSelected || (showCorrectAnswer && isCorrect)) 16.dp else 16.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = optionText,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.weight(1f),
maxLines = Int.MAX_VALUE
)
}
// Show Check/Close icon on top
if (isSelected || (showCorrectAnswer && isCorrect)) {
val icon = if (isCorrect) Icons.Default.Check else Icons.Default.Close
val iconColor = if (isCorrect) AppColors.CorrectGreen else AppColors.IncorrectRed
Icon(
imageVector = icon,
contentDescription = null,
tint = iconColor,
modifier = Modifier.size(24.dp).padding(start = 4.dp)
)
}
}
}
}
@Composable
fun ExplanationButton(
explanation: String,
showExplanation: Boolean,
onToggleExplanation: () -> Unit,
currentQuestionState: MCQViewModel.QuestionState
) {
if (currentQuestionState.hasAnswered) {
Button(
onClick = onToggleExplanation,
modifier = Modifier.padding(8.dp),
enabled = currentQuestionState.hasAnswered
) {
Text("Explanation")
}
if (showExplanation) {
Text(
text = explanation,
modifier = Modifier.padding(12.dp)
)
}
}
}
i was expecting to see when the styled text or math formula are in between the sentences of lets say questionText field in firestore in text but when i tried i would only show the styled word like a word in italic while all the remaining normal text did not show