Created
October 4, 2023 06:38
-
-
Save damiancastelao/a33af458aafc9635e967d49871f2c036 to your computer and use it in GitHub Desktop.
mutableState
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
@Composable | |
fun Login() { | |
// Dos maneras diferentes de definir un estado | |
// con el = necesitamos utilizar value | |
var counter by remember { mutableStateOf(0) } | |
var name = remember { mutableStateOf("") } | |
Column { | |
// mostrar el contador de clics | |
TextButton(onClick = { counter++ }) { | |
Text("CLICS: $counter") | |
} | |
// mientras no tecleamos mas de tres caracteres no se muestra el saludo | |
if (name.value.length > 3) { | |
Text( | |
text = "Nombre: ${name.value}!", | |
fontSize = 24.sp | |
) | |
} | |
// campo de texto para rellenar | |
OutlinedTextField( | |
value = name.value, | |
onValueChange = { | |
name.value = it | |
}, | |
label = { Text(text = "Name") } | |
) | |
} | |
// creamos otro widget para mostrar el saludo | |
Greeting(name = name.value) | |
} | |
@Composable | |
fun Greeting(name: String, modifier: Modifier = Modifier) { | |
Column { | |
Text( | |
text = "Hello $name!", | |
fontSize = 38.sp, | |
// lo separamos del borde superior | |
modifier = Modifier.padding(vertical = 150.dp) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment