What's Happening?
So I have this column which has two mutable objects of type LocalTime
. I am updated both in the TwoLineButton()
method. Then I have this method ShowTimeRangeText()
which displays a Text if both LocalTime objects are anything other than null. It's a simple condition.
Column() {
val selectedTimeStart = remember { mutableStateOf<LocalTime?>(null) }
val selectedTimeEnd = remember { mutableStateOf<LocalTime?>(null) }
Row(modifier = Modifier.padding(start = 8.dp, end = 8.dp)) {
TwoLineButton(txt1 = "Start Time", txt2 = "-- : --", selectedTimeStart)
Spacer(modifier = Modifier.weight(0.05f))
TwoLineButton(txt1 = "End Time", txt2 = "-- : --", selectedTimeEnd)
}
ShowTimeRangeText(selectedTimeStart,selectedTimeEnd)
}
@Composable
private fun ShowTimeRangeText(
selectedTimeStart: MutableState<LocalTime?>,
selectedTimeEnd: MutableState<LocalTime?>
) {
if (selectedTimeStart.value != null && selectedTimeEnd.value != null){
Timber.d("Text Can be shown")
Text(text = "Some text")
}
}
@Composable
fun TwoLineButton(
txt1: String, txt2: String, selectedTime: MutableState<LocalTime?> = remember {
mutableStateOf(null)
}
) {
val sheetState = rememberSheetState()
val title = remember {
mutableStateOf(txt1)
}
OpenClock(sheetState, title, selectedTime)
Button(onClick = {
sheetState.show()
}) {
Column {
Text(
text = txt1,
textAlign = TextAlign.Center,
modifier = Modifier.width(80.dp)
)
Text(
text = if (selectedTime.value == null) txt2 else selectedTime.value.toString(),
textAlign = TextAlign.Center,
modifier = Modifier.width(80.dp)
)
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OpenClock(
sheetState: com.maxkeppeker.sheets.core.models.base.SheetState,
title: MutableState<String>,
selectedTime: MutableState<LocalTime?>
) {
ClockDialog(
header = Header.Default(title.value),
state = sheetState,
selection = ClockSelection.HoursMinutes { hours, minutes ->
Timber.d("Time Selected")
selectedTime.value = LocalTime.of(hours, minutes)
},
config = ClockConfig(
is24HourFormat = false,
),
)
}
What's the issue?
If i put the method ShowTimeRangeText()
inside my Row()
the the text is being displayed according to the condition. But If I put the method outside of Row()
then the text is not showing at all (even if the condition is true and the log is printing)
I've tried showing the text without the conditon. And it shows. Tried moving the row and the text outside the column but still nothing happend.
I was expecting to show the text within the condition.