Created
June 25, 2025 04:37
-
-
Save danielcristho/1c64c4c810a5a1774ee785e5ac05c96b to your computer and use it in GitHub Desktop.
Auth
This file contains hidden or 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
| package com.example.starbucksclone // Sesuaikan dengan package name Anda | |
| import androidx.compose.foundation.Image | |
| import androidx.compose.foundation.layout.* | |
| import androidx.compose.foundation.shape.RoundedCornerShape | |
| import androidx.compose.foundation.text.ClickableText | |
| import androidx.compose.foundation.text.KeyboardOptions | |
| import androidx.compose.material3.* | |
| import androidx.compose.runtime.* | |
| import androidx.compose.ui.Alignment | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.graphics.Color | |
| import androidx.compose.ui.res.painterResource | |
| import androidx.compose.ui.text.AnnotatedString | |
| import androidx.compose.ui.text.TextStyle | |
| import androidx.compose.ui.text.font.FontWeight | |
| import androidx.compose.ui.text.input.KeyboardType | |
| import androidx.compose.ui.text.input.PasswordVisualTransformation | |
| import androidx.compose.ui.tooling.preview.Preview | |
| import androidx.compose.ui.unit.dp | |
| import androidx.compose.ui.unit.sp | |
| import androidx.navigation.NavController | |
| import androidx.navigation.compose.rememberNavController | |
| @Composable | |
| fun LoginScreen(navController: NavController) { | |
| var email by remember { mutableStateOf("") } | |
| var password by remember { mutableStateOf("") } | |
| Column( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .padding(30.dp), | |
| verticalArrangement = Arrangement.Center, | |
| horizontalAlignment = Alignment.CenterHorizontally | |
| ) { | |
| // Logo Starbucks | |
| Image( | |
| painter = painterResource(id = R.drawable.starbucks_logo), | |
| contentDescription = "Starbucks Logo", | |
| modifier = Modifier.size(150.dp) | |
| ) | |
| Spacer(modifier = Modifier.height(20.dp)) | |
| Text( | |
| text = "Selamat Datang Kembali!", | |
| style = TextStyle(fontSize = 28.sp, fontWeight = FontWeight.Bold) | |
| ) | |
| Spacer(modifier = Modifier.height(40.dp)) | |
| // Input field untuk Email | |
| OutlinedTextField( | |
| value = email, | |
| onValueChange = { email = it }, | |
| label = { Text("Email") }, | |
| modifier = Modifier.fillMaxWidth(), | |
| keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email), | |
| singleLine = true | |
| ) | |
| Spacer(modifier = Modifier.height(16.dp)) | |
| // Input field untuk Password | |
| OutlinedTextField( | |
| value = password, | |
| onValueChange = { password = it }, | |
| label = { Text("Password") }, | |
| modifier = Modifier.fillMaxWidth(), | |
| visualTransformation = PasswordVisualTransformation(), | |
| keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), | |
| singleLine = true | |
| ) | |
| Spacer(modifier = Modifier.height(30.dp)) | |
| // Tombol Login | |
| Button( | |
| onClick = { | |
| navController.navigate(Screen.Home.route) { | |
| // Membersihkan back stack agar tidak bisa kembali ke login | |
| popUpTo(Screen.Login.route) { inclusive = true } | |
| } | |
| }, | |
| modifier = Modifier | |
| .fillMaxWidth() | |
| .height(50.dp), | |
| shape = RoundedCornerShape(10.dp), | |
| colors = ButtonDefaults.buttonColors( | |
| containerColor = Color(0xFF006241) // Warna hijau khas Starbucks | |
| ) | |
| ) { | |
| Text(text = "Login", fontSize = 18.sp) | |
| } | |
| Spacer(modifier = Modifier.height(20.dp)) | |
| // Teks untuk ke halaman Register | |
| ClickableText( | |
| text = AnnotatedString("Belum punya akun? Daftar di sini"), | |
| onClick = { | |
| navController.navigate(Screen.Register.route) | |
| }, | |
| style = TextStyle( | |
| fontSize = 14.sp, | |
| color = Color.Gray | |
| ) | |
| ) | |
| } | |
| } | |
| @Preview(showBackground = true) | |
| @Composable | |
| fun LoginScreenPreview() { | |
| LoginScreen(navController = rememberNavController()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment