271 lines
9.8 KiB
Dart
271 lines
9.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import '../widgets/fade_in_up.dart';
|
|
|
|
class RegisterScreen extends StatefulWidget {
|
|
const RegisterScreen({super.key});
|
|
|
|
@override
|
|
State<RegisterScreen> createState() => _RegisterScreenState();
|
|
}
|
|
|
|
class _RegisterScreenState extends State<RegisterScreen> {
|
|
final nameController = TextEditingController();
|
|
final emailController = TextEditingController();
|
|
final passwordController = TextEditingController();
|
|
final confirmController = TextEditingController();
|
|
|
|
bool loading = false;
|
|
bool hidePassword = true;
|
|
bool hideConfirmPassword = true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
body: Stack(
|
|
children: [
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
stops: [0.0, 0.4, 0.7, 1.0],
|
|
colors: [
|
|
Color(0xFFE8F5E9),
|
|
Color(0xFFFFFDF0),
|
|
Color(0xFFF1F8E9),
|
|
Color(0xFFE8F5E9),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
SafeArea(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 25),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
|
|
// --- TITLE & SUBTITLE ---
|
|
FadeInUp(
|
|
delay: 0,
|
|
child: Column(
|
|
children: const [
|
|
Text(
|
|
"Create Account",
|
|
style: TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF2E7D32),
|
|
),
|
|
),
|
|
SizedBox(height: 12),
|
|
Text(
|
|
"daftar terlebih dahulu untuk memulai fermentasi.",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: Colors.black54,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
// --- FORM CARD ---
|
|
FadeInUp(
|
|
delay: 150,
|
|
child: Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(30),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.08),
|
|
blurRadius: 30,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildInput(
|
|
controller: nameController,
|
|
hint: "Full name",
|
|
icon: Icons.person_outline_rounded,
|
|
),
|
|
const SizedBox(height: 15),
|
|
_buildInput(
|
|
controller: emailController,
|
|
hint: "Email",
|
|
icon: Icons.email_outlined,
|
|
keyboardType: TextInputType.emailAddress,
|
|
),
|
|
const SizedBox(height: 15),
|
|
_buildInput(
|
|
controller: passwordController,
|
|
hint: "Password",
|
|
icon: Icons.lock_outline_rounded,
|
|
isPassword: true,
|
|
obscure: hidePassword,
|
|
onToggle: () =>
|
|
setState(() => hidePassword = !hidePassword),
|
|
),
|
|
const SizedBox(height: 15),
|
|
_buildInput(
|
|
controller: confirmController,
|
|
hint: "Confirm password",
|
|
icon: Icons.lock_outline_rounded,
|
|
isPassword: true,
|
|
obscure: hideConfirmPassword,
|
|
onToggle: () => setState(
|
|
() => hideConfirmPassword = !hideConfirmPassword,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 35),
|
|
|
|
// --- REGISTER BUTTON ---
|
|
FadeInUp(
|
|
delay: 300,
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: 65,
|
|
child: ElevatedButton(
|
|
onPressed: loading ? null : _register,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF2E7D32),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: loading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
"Register",
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
SizedBox(width: 15),
|
|
Icon(Icons.arrow_right_alt_rounded, size: 30),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
// Link kembali ke login
|
|
// --- LINK KE LOGIN (DIUBAH) ---
|
|
FadeInUp(
|
|
delay: 450,
|
|
child: TextButton(
|
|
onPressed: () {
|
|
// Gunakan pushReplacementNamed agar tidak menumpuk di stack
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
},
|
|
child: const Text(
|
|
"Sudah punya akun? Login",
|
|
style: TextStyle(color: Colors.black45),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- WIDGET HELPER: INPUT FIELD ---
|
|
Widget _buildInput({
|
|
required TextEditingController controller,
|
|
required String hint,
|
|
required IconData icon,
|
|
bool isPassword = false,
|
|
bool obscure = false,
|
|
VoidCallback? onToggle,
|
|
TextInputType keyboardType = TextInputType.text,
|
|
}) {
|
|
return TextField(
|
|
controller: controller,
|
|
obscureText: obscure,
|
|
keyboardType: keyboardType,
|
|
decoration: InputDecoration(
|
|
hintText: hint,
|
|
hintStyle: const TextStyle(color: Colors.black38),
|
|
prefixIcon: Icon(icon, color: Colors.black87),
|
|
suffixIcon: isPassword
|
|
? IconButton(
|
|
icon: Icon(
|
|
obscure
|
|
? Icons.visibility_off_outlined
|
|
: Icons.visibility_outlined,
|
|
color: Colors.black87,
|
|
),
|
|
onPressed: onToggle,
|
|
)
|
|
: null,
|
|
filled: true,
|
|
fillColor: const Color(
|
|
0xFFE8F5E9,
|
|
).withOpacity(0.5), // Warna biru muda di desain
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
vertical: 20,
|
|
horizontal: 20,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
Future<void> _register() async {
|
|
if (passwordController.text != confirmController.text) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text("Password tidak sama")));
|
|
return;
|
|
}
|
|
setState(() => loading = true);
|
|
try {
|
|
await FirebaseAuth.instance.createUserWithEmailAndPassword(
|
|
email: emailController.text.trim(),
|
|
password: passwordController.text.trim(),
|
|
);
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
} catch (e) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(e.toString())));
|
|
}
|
|
setState(() => loading = false);
|
|
}
|
|
}
|