152 lines
5.6 KiB
Dart
152 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../services/supabase_service.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();
|
|
bool _isLoading = false;
|
|
|
|
Future<void> _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: true,
|
|
style: const TextStyle(color: Colors.white),
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(Icons.lock, color: Colors.green),
|
|
suffixIcon: Icon(Icons.visibility, color: Colors.grey),
|
|
hintText: 'Password',
|
|
hintStyle: 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),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|