TKK_E32231503/lib/screens/register_screen.dart

227 lines
8.1 KiB
Dart

import 'package:flutter/material.dart';
import 'login_screen.dart';
class RegisterScreen extends StatefulWidget {
const RegisterScreen({super.key});
@override
RegisterScreenState createState() => RegisterScreenState();
}
class RegisterScreenState extends State<RegisterScreen> {
final _namaController = TextEditingController();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _konfirmasiController = TextEditingController();
bool _obscurePassword = true;
bool _obscureKonfirmasi = true;
void _register() {
String nama = _namaController.text.trim();
String email = _emailController.text.trim();
String password = _passwordController.text.trim();
String konfirmasi = _konfirmasiController.text.trim();
if (nama.isEmpty || email.isEmpty || password.isEmpty || konfirmasi.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Semua kolom harus diisi!")),
);
return;
}
if (password != konfirmasi) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Password tidak cocok!")),
);
return;
}
// Simulasi register berhasil → kembali ke Login
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Registrasi berhasil! Silakan login.")),
);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const LoginScreen()),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green.shade50,
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(28),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// ── Icon ────────────────────────────────────
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.green.shade200,
blurRadius: 20,
spreadRadius: 4,
)
],
),
child: const Icon(Icons.person_add, size: 60, color: Colors.white),
),
const SizedBox(height: 24),
const Text(
"Buat Akun Baru",
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: Colors.green,
),
),
const Text(
"Daftarkan diri Anda",
style: TextStyle(fontSize: 14, color: Colors.grey),
),
const SizedBox(height: 32),
// ── Card Form ────────────────────────────────
Card(
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
children: [
// Nama
TextField(
controller: _namaController,
decoration: InputDecoration(
labelText: "Nama Lengkap",
prefixIcon: const Icon(Icons.person_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 16),
// Email
TextField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "Email",
prefixIcon: const Icon(Icons.email_outlined),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 16),
// Password
TextField(
controller: _passwordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: "Password",
prefixIcon: const Icon(Icons.lock_outline),
suffixIcon: IconButton(
icon: Icon(_obscurePassword
? Icons.visibility_off
: Icons.visibility),
onPressed: () => setState(
() => _obscurePassword = !_obscurePassword),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 16),
// Konfirmasi Password
TextField(
controller: _konfirmasiController,
obscureText: _obscureKonfirmasi,
decoration: InputDecoration(
labelText: "Konfirmasi Password",
prefixIcon: const Icon(Icons.lock_reset_outlined),
suffixIcon: IconButton(
icon: Icon(_obscureKonfirmasi
? Icons.visibility_off
: Icons.visibility),
onPressed: () => setState(
() => _obscureKonfirmasi = !_obscureKonfirmasi),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 24),
// Tombol Daftar
SizedBox(
width: double.infinity,
height: 48,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
onPressed: _register,
child: const Text(
"Daftar",
style: TextStyle(fontSize: 16, color: Colors.white),
),
),
),
],
),
),
),
const SizedBox(height: 20),
// ── Link ke Login ────────────────────────────
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Sudah punya akun? "),
GestureDetector(
onTap: () => Navigator.pop(context),
child: const Text(
"Masuk",
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
),
);
}
}