import 'package:flutter/material.dart'; import '../services/supabase_service.dart'; class RegisterScreen extends StatefulWidget { const RegisterScreen({super.key}); @override State createState() => _RegisterScreenState(); } class _RegisterScreenState extends State { final _nameController = TextEditingController(); final _emailController = TextEditingController(); final _passwordController = TextEditingController(); bool _isLoading = false; bool _obscurePassword = true; // Tambahan: State untuk mata password Future _handleRegister() async { setState(() => _isLoading = true); try { await SupabaseService().signUp( _emailController.text.trim(), _passwordController.text.trim(), _nameController.text.trim(), ); if (mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Registration successful! Please login.')), ); Navigator.pop(context); } } catch (e) { if (mounted) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Error: $e'), backgroundColor: Colors.red), ); } } finally { if (mounted) setState(() => _isLoading = false); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, appBar: AppBar( backgroundColor: Colors.transparent, elevation: 0, leading: IconButton( icon: const Icon(Icons.arrow_back, color: Colors.green), onPressed: () => Navigator.pop(context), ), ), body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 30.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'Buat Akun Baru', style: TextStyle(color: Colors.green, fontSize: 32, fontWeight: FontWeight.bold), ), const Text( 'Lengkapi data diri Anda untuk memulai', style: TextStyle(color: Colors.grey, fontSize: 16), ), const SizedBox(height: 50), Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(25), border: Border.all(color: Colors.grey.withOpacity(0.3)), ), child: Column( children: [ TextField( controller: _nameController, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( prefixIcon: Icon(Icons.person, color: Colors.green), hintText: 'Nama Lengkap', hintStyle: TextStyle(color: Colors.grey), border: InputBorder.none, ), ), const Divider(color: Colors.grey), TextField( controller: _emailController, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( prefixIcon: Icon(Icons.email, color: Colors.green), hintText: 'Email', hintStyle: TextStyle(color: Colors.grey), border: InputBorder.none, ), ), const Divider(color: Colors.grey), TextField( controller: _passwordController, obscureText: _obscurePassword, // Menggunakan variabel state style: const TextStyle(color: Colors.white), decoration: InputDecoration( prefixIcon: const Icon(Icons.lock, color: Colors.green), // Menggunakan IconButton untuk aksi klik suffixIcon: IconButton( icon: Icon( _obscurePassword ? Icons.visibility : Icons.visibility_off, color: Colors.grey, ), onPressed: () { setState(() { _obscurePassword = !_obscurePassword; }); }, ), hintText: 'Password', hintStyle: const TextStyle(color: Colors.grey), border: InputBorder.none, ), ), const SizedBox(height: 30), SizedBox( width: double.infinity, height: 55, child: ElevatedButton( onPressed: _isLoading ? null : _handleRegister, style: ElevatedButton.styleFrom( backgroundColor: Colors.green, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), ), ), child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : const Text( 'Daftar Sekarang', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white), ), ), ), ], ), ), const SizedBox(height: 30), Center( child: TextButton( onPressed: () => Navigator.pop(context), child: const Text( 'Sudah punya akun? Masuk', style: TextStyle(color: Colors.green), ), ), ), ], ), ), ), ); } }