Looking at a huge number of lines-of-code to do a basic task:
First the imports:
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.ui.tooling.preview.Preview
Then the TextFields:
@Composable
fun EmailTextField() {
var email by rememberSaveable { mutableStateOf("") }
TextField(
value = email,
onValueChange = { email = it },
label = { Text("Enter email") }
)
}
@Composable
fun PasswordTextField() {
var password by rememberSaveable { mutableStateOf("") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Enter password") },
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
}
Finally the App itself:
@OptIn(ExperimentalResourceApi::class)
@Composable
@Preview
fun App() {
MaterialTheme {
var showContent by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
EmailTextField()
PasswordTextField()
Button(onClick = { showContent = !showContent }) {
Text("Auth")
}
}
}
}
Trying to get the email and password, pass it to a function that does an HTTP request and based on the output, navigate to a welcome screen or display the error.
14 files is what the official compose example project shows to solve this problem (and it doesn't even do the HTTP request/response).
Is there not just a simple way of getting the email+password and navigating to the next thing on form submission?