Gamar Mustafa
11/26/2024, 7:28 AMfun updateIdValue(type: Type, value: String = "") {
val updatedValue = when (type) {
Type.OBJECT ->{
val cleanedValue = value.replace("-","")
when {
cleanedValue.length < 10 -> cleanedValue
else -> {
val firstPart = cleanedValue.take(10)
val secondPart = cleanedValue.drop(10).take(5)
if (secondPart.isNotEmpty()) {
"$firstPart-$secondPart"
} else {
firstPart
}
}
}
}
else -> value
}
_idValue.value = updatedValue
}
ephemient
11/26/2024, 7:33 AM.value
makes it appear you may be using MutableStateFlow
, in which case: have you read https://medium.com/androiddevelopers/effective-state-management-for-textfield-in-compose-d6e5b070fbe5
Avoid using reactive streams (e.g.) to represent yourStateFlow
stateTextField
Gamar Mustafa
11/26/2024, 7:36 AMephemient
11/26/2024, 7:36 AMTextField
with a https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/VisualTransformation to insert the hyphen is what you should probably useGamar Mustafa
11/26/2024, 7:41 AMAhmed
11/26/2024, 9:56 AM.value
can also indicate a MutableState
, ephemient.
Gamar Mustafa, the visual transformation from docs gives an example of credit cards. Your use-case is similar.