Created
August 27, 2023 21:42
-
-
Save waseefakhtar/5065898e9e54cb687e898a211c1e1d87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalMaterial3Api::class) | |
@Composable | |
fun AddMedicationScreen() { | |
// Previously implememted. | |
var numberOfDosage by rememberSaveable { mutableStateOf("1") } | |
var recurrence by rememberSaveable { mutableStateOf(Recurrence.Daily.name) } | |
Column( | |
modifier = Modifier | |
.padding(16.dp, 16.dp) | |
.verticalScroll(rememberScrollState()), | |
verticalArrangement = Arrangement.spacedBy(8.dp) | |
) { | |
// Previously implememted. | |
Spacer(modifier = Modifier.padding(4.dp)) | |
var isMaxDoseError by rememberSaveable { mutableStateOf(false) } | |
Row( | |
horizontalArrangement = Arrangement.spacedBy(16.dp) | |
) { | |
val maxDose = 3 | |
Column( | |
verticalArrangement = Arrangement.spacedBy(8.dp) | |
) { | |
Text( | |
text = stringResource(id = R.string.dosage), | |
style = MaterialTheme.typography.bodyLarge | |
) | |
TextField( | |
modifier = Modifier.width(128.dp), | |
value = numberOfDosage, | |
onValueChange = { | |
if (it.length < maxDose) { | |
isMaxDoseError = false | |
numberOfDosage = it | |
} else { | |
isMaxDoseError = true | |
} | |
}, | |
trailingIcon = { | |
if (isMaxDoseError) { | |
Icon( | |
imageVector = Icons.Filled.Info, | |
contentDescription = "Error", | |
tint = MaterialTheme.colorScheme.error | |
) | |
} | |
}, | |
placeholder = { Text(text = "e.g. 1") }, | |
isError = isMaxDoseError, | |
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number) | |
) | |
} | |
RecurrenceDropdownMenu { recurrence = it } | |
} | |
if (isMaxDoseError) { | |
Text( | |
text = "You cannot have more than 99 dosage per day.", | |
color = MaterialTheme.colorScheme.error, | |
style = MaterialTheme.typography.bodySmall, | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment