Tambahkan dependensi dan konfigurasi awal proyek

- Tambahkan dependensi utama: GetX, Supabase, SharedPreferences
- Konfigurasi struktur awal aplikasi dengan GetX
- Inisialisasi layanan Supabase
- Perbarui konfigurasi plugin untuk berbagai platform
- Ganti template default dengan struktur aplikasi baru
This commit is contained in:
Khafidh Fuadi
2025-03-08 10:20:57 +07:00
parent c5d0805e50
commit b1665307c5
28 changed files with 3259 additions and 112 deletions

View File

@ -0,0 +1,11 @@
import 'package:get/get.dart';
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
class AuthBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<AuthController>(
() => AuthController(),
);
}
}

View File

@ -0,0 +1,512 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:penyaluran_app/app/data/models/user_model.dart';
import 'package:penyaluran_app/app/data/providers/auth_provider.dart';
import 'package:penyaluran_app/app/routes/app_pages.dart';
class AuthController extends GetxController {
static AuthController get to => Get.find();
final AuthProvider _authProvider = AuthProvider();
final Rx<UserModel?> _user = Rx<UserModel?>(null);
UserModel? get user => _user.value;
final RxBool isLoading = false.obs;
final RxBool isWargaProfileComplete = false.obs;
// Form controllers
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
final TextEditingController confirmPasswordController =
TextEditingController();
// Form controllers untuk data warga
final TextEditingController nikController = TextEditingController();
final TextEditingController namaLengkapController = TextEditingController();
final TextEditingController jenisKelaminController = TextEditingController();
final TextEditingController noHpController = TextEditingController();
final TextEditingController alamatController = TextEditingController();
final TextEditingController tempatLahirController = TextEditingController();
final TextEditingController tanggalLahirController = TextEditingController();
final TextEditingController agamaController = TextEditingController();
// Form keys
final GlobalKey<FormState> loginFormKey = GlobalKey<FormState>();
final GlobalKey<FormState> registerFormKey = GlobalKey<FormState>();
final GlobalKey<FormState> wargaProfileFormKey = GlobalKey<FormState>();
@override
void onInit() {
super.onInit();
// Tambahkan penundaan kecil untuk menghindari loop navigasi
Future.delayed(const Duration(milliseconds: 100), () {
checkAuthStatus();
});
}
@override
void onClose() {
// Pastikan semua controller dibersihkan sebelum dilepaskan
clearAndDisposeControllers();
super.onClose();
}
// Metode untuk membersihkan dan melepaskan controller
void clearAndDisposeControllers() {
try {
if (emailController.text.isNotEmpty) emailController.clear();
if (passwordController.text.isNotEmpty) passwordController.clear();
if (confirmPasswordController.text.isNotEmpty)
confirmPasswordController.clear();
if (nikController.text.isNotEmpty) nikController.clear();
if (namaLengkapController.text.isNotEmpty) namaLengkapController.clear();
if (jenisKelaminController.text.isNotEmpty)
jenisKelaminController.clear();
if (noHpController.text.isNotEmpty) noHpController.clear();
if (alamatController.text.isNotEmpty) alamatController.clear();
if (tempatLahirController.text.isNotEmpty) tempatLahirController.clear();
if (tanggalLahirController.text.isNotEmpty)
tanggalLahirController.clear();
if (agamaController.text.isNotEmpty) agamaController.clear();
emailController.dispose();
passwordController.dispose();
confirmPasswordController.dispose();
nikController.dispose();
namaLengkapController.dispose();
jenisKelaminController.dispose();
noHpController.dispose();
alamatController.dispose();
tempatLahirController.dispose();
tanggalLahirController.dispose();
agamaController.dispose();
} catch (e) {
print('Error disposing controllers: $e');
}
}
// Memeriksa status autentikasi
Future<void> checkAuthStatus() async {
isLoading.value = true;
try {
final currentUser = await _authProvider.getCurrentUser();
if (currentUser != null) {
_user.value = currentUser;
// Periksa apakah profil warga sudah lengkap
await checkWargaProfileStatus();
// Hindari navigasi jika sudah berada di halaman yang sesuai
final currentRoute = Get.currentRoute;
// Untuk semua role, arahkan ke dashboard masing-masing
final targetRoute = _getTargetRouteForRole(currentUser.role);
if (currentRoute != targetRoute) {
navigateBasedOnRole(currentUser.role);
}
} else {
// Jika tidak ada user yang login, arahkan ke halaman login
if (Get.currentRoute != Routes.LOGIN) {
// Bersihkan dependensi form sebelum navigasi
clearFormDependencies();
Get.offAllNamed(Routes.LOGIN);
}
}
} catch (e) {
print('Error checking auth status: $e');
// Jika terjadi error, arahkan ke halaman login
if (Get.currentRoute != Routes.LOGIN) {
// Bersihkan dependensi form sebelum navigasi
clearFormDependencies();
Get.offAllNamed(Routes.LOGIN);
}
} finally {
isLoading.value = false;
}
}
// Memeriksa status profil warga
Future<void> checkWargaProfileStatus() async {
try {
if (_user.value?.role == 'WARGA') {
final wargaData = await _authProvider.getWargaData();
isWargaProfileComplete.value = wargaData != null;
} else {
isWargaProfileComplete.value = true;
}
} catch (e) {
print('Error checking warga profile: $e');
isWargaProfileComplete.value = false;
}
}
// Metode untuk membersihkan dependensi form
void clearFormDependencies() {
try {
// Hapus fokus dari semua field
FocusManager.instance.primaryFocus?.unfocus();
// Reset form state jika ada
loginFormKey.currentState?.reset();
registerFormKey.currentState?.reset();
wargaProfileFormKey.currentState?.reset();
} catch (e) {
print('Error clearing form dependencies: $e');
}
}
// Metode untuk navigasi berdasarkan peran
void navigateBasedOnRole(String role) {
// Bersihkan dependensi form sebelum navigasi
clearFormDependencies();
switch (role) {
case 'WARGA':
Get.offAllNamed(Routes.WARGA_DASHBOARD);
break;
case 'PETUGASVERIFIKASI':
Get.offAllNamed(Routes.PETUGAS_VERIFIKASI_DASHBOARD);
break;
case 'PETUGASDESA':
Get.offAllNamed(Routes.PETUGAS_DESA_DASHBOARD);
break;
case 'DONATUR':
Get.offAllNamed(Routes.DONATUR_DASHBOARD);
break;
default:
Get.offAllNamed(Routes.HOME);
break;
}
}
// Metode untuk login
Future<void> login() async {
if (!loginFormKey.currentState!.validate()) return;
// Simpan nilai dari controller sebelum melakukan operasi asinkron
final email = emailController.text.trim();
final password = passwordController.text;
try {
isLoading.value = true;
final user = await _authProvider.signIn(
email,
password,
);
if (user != null) {
_user.value = user;
clearControllers();
// Periksa apakah profil warga sudah lengkap
await checkWargaProfileStatus();
// Arahkan ke dashboard sesuai peran
navigateBasedOnRole(user.role);
// Tampilkan notifikasi jika profil belum lengkap untuk warga
if (user.role == 'WARGA' && !isWargaProfileComplete.value) {
Get.snackbar(
'Informasi',
'Profil Anda belum lengkap. Silakan lengkapi profil Anda melalui menu Profil',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.blue,
colorText: Colors.white,
duration: const Duration(seconds: 5),
);
} else {
Get.snackbar(
'Berhasil',
'Login berhasil',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
colorText: Colors.white,
);
}
}
} catch (e) {
print('Error login: $e');
Get.snackbar(
'Error',
'Login gagal: ${e.toString()}',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
} finally {
isLoading.value = false;
}
}
// Metode untuk register
Future<void> register() async {
if (!registerFormKey.currentState!.validate()) return;
// Simpan nilai dari controller sebelum melakukan operasi asinkron
final email = emailController.text.trim();
final password = passwordController.text;
final confirmPassword = confirmPasswordController.text;
if (password != confirmPassword) {
Get.snackbar(
'Error',
'Password dan konfirmasi password tidak sama',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
return;
}
try {
isLoading.value = true;
final user = await _authProvider.signUp(
email,
password,
);
if (user != null) {
_user.value = user;
clearControllers();
// Periksa status profil
await checkWargaProfileStatus();
// Arahkan ke dashboard sesuai peran
navigateBasedOnRole(user.role);
// Tampilkan notifikasi untuk melengkapi profil
Get.snackbar(
'Berhasil',
'Registrasi berhasil. Silakan lengkapi profil Anda melalui menu Profil',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
colorText: Colors.white,
duration: const Duration(seconds: 5),
);
}
} catch (e) {
Get.snackbar(
'Error',
'Registrasi gagal: ${e.toString()}',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
} finally {
isLoading.value = false;
}
}
// Metode untuk melengkapi profil warga
Future<void> completeWargaProfile() async {
if (!wargaProfileFormKey.currentState!.validate()) return;
// Simpan nilai dari controller sebelum melakukan operasi asinkron
final nik = nikController.text.trim();
final namaLengkap = namaLengkapController.text.trim();
final jenisKelamin = jenisKelaminController.text.trim();
final noHp = noHpController.text.trim();
final alamat = alamatController.text.trim();
final tempatLahir = tempatLahirController.text.trim();
final tanggalLahirText = tanggalLahirController.text;
final agama = agamaController.text.trim();
try {
isLoading.value = true;
DateTime? tanggalLahir;
if (tanggalLahirText.isNotEmpty) {
try {
final parts = tanggalLahirText.split('-');
if (parts.length == 3) {
tanggalLahir = DateTime(
int.parse(parts[2]), // tahun
int.parse(parts[1]), // bulan
int.parse(parts[0]), // hari
);
}
} catch (e) {
print('Error parsing date: $e');
}
}
await _authProvider.createWargaProfile(
nik: nik,
namaLengkap: namaLengkap,
jenisKelamin: jenisKelamin,
noHp: noHp,
alamat: alamat,
tempatLahir: tempatLahir,
tanggalLahir: tanggalLahir,
agama: agama,
);
isWargaProfileComplete.value = true;
// Kembali ke halaman sebelumnya jika menggunakan Get.toNamed
if (Get.previousRoute.isNotEmpty) {
Get.back();
Get.snackbar(
'Berhasil',
'Profil berhasil dilengkapi',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
colorText: Colors.white,
);
} else {
// Jika tidak ada halaman sebelumnya, navigasi ke dashboard warga
Get.offAllNamed(Routes.WARGA_DASHBOARD);
Get.snackbar(
'Berhasil',
'Profil berhasil dilengkapi',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
colorText: Colors.white,
);
}
} catch (e) {
Get.snackbar(
'Error',
'Gagal melengkapi profil: ${e.toString()}',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
} finally {
isLoading.value = false;
}
}
// Metode untuk logout
Future<void> logout() async {
try {
await _authProvider.signOut();
_user.value = null;
isWargaProfileComplete.value = false;
// Bersihkan dependensi form sebelum navigasi
clearFormDependencies();
Get.offAllNamed(Routes.LOGIN);
} catch (e) {
Get.snackbar(
'Error',
'Logout gagal: ${e.toString()}',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
}
}
// Metode untuk membersihkan controller
void clearControllers() {
try {
if (emailController.text.isNotEmpty) emailController.clear();
if (passwordController.text.isNotEmpty) passwordController.clear();
if (confirmPasswordController.text.isNotEmpty)
confirmPasswordController.clear();
} catch (e) {
print('Error clearing controllers: $e');
}
}
// Validasi email
String? validateEmail(String? value) {
if (value == null || value.isEmpty) {
return 'Email tidak boleh kosong';
}
if (!GetUtils.isEmail(value)) {
return 'Email tidak valid';
}
return null;
}
// Validasi password
String? validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password tidak boleh kosong';
}
if (value.length < 6) {
return 'Password minimal 6 karakter';
}
return null;
}
// Validasi konfirmasi password
String? validateConfirmPassword(String? value) {
try {
if (value == null || value.isEmpty) {
return 'Konfirmasi password tidak boleh kosong';
}
// Ambil nilai password dari controller jika tersedia
final password = passwordController.text;
if (value != password) {
return 'Password dan konfirmasi password tidak sama';
}
return null;
} catch (e) {
print('Error validating confirm password: $e');
return 'Terjadi kesalahan saat validasi';
}
}
// Validasi NIK
String? validateNIK(String? value) {
if (value == null || value.isEmpty) {
return 'NIK tidak boleh kosong';
}
if (value.length != 16) {
return 'NIK harus 16 digit';
}
if (!GetUtils.isNumericOnly(value)) {
return 'NIK harus berupa angka';
}
return null;
}
// Validasi nama lengkap
String? validateNamaLengkap(String? value) {
if (value == null || value.isEmpty) {
return 'Nama lengkap tidak boleh kosong';
}
return null;
}
// Validasi jenis kelamin
String? validateJenisKelamin(String? value) {
if (value == null || value.isEmpty) {
return 'Jenis kelamin tidak boleh kosong';
}
return null;
}
// Mendapatkan rute target berdasarkan peran
String _getTargetRouteForRole(String role) {
switch (role) {
case 'WARGA':
return Routes.WARGA_DASHBOARD;
case 'PETUGASVERIFIKASI':
return Routes.PETUGAS_VERIFIKASI_DASHBOARD;
case 'PETUGASDESA':
return Routes.PETUGAS_DESA_DASHBOARD;
case 'DONATUR':
return Routes.DONATUR_DASHBOARD;
default:
return Routes.HOME;
}
}
// Metode untuk navigasi ke halaman lengkapi profil
void navigateToCompleteProfile() {
// Bersihkan dependensi form sebelum navigasi
clearFormDependencies();
// Gunakan preventDuplicates untuk mencegah navigasi berulang
Get.toNamed(Routes.COMPLETE_PROFILE, preventDuplicates: true);
}
}

View File

@ -0,0 +1,270 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
class CompleteProfileView extends GetView<AuthController> {
const CompleteProfileView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Lengkapi Profil'),
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => Get.back(),
),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: Form(
key: controller.wargaProfileFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 10),
const Center(
child: Text(
'Lengkapi Data Diri Anda',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
),
const SizedBox(height: 5),
const Center(
child: Text(
'Data ini diperlukan untuk verifikasi',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
),
const SizedBox(height: 30),
// NIK Field
TextFormField(
controller: controller.nikController,
keyboardType: TextInputType.number,
maxLength: 16,
decoration: InputDecoration(
labelText: 'NIK',
prefixIcon: const Icon(Icons.credit_card),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validateNIK,
),
const SizedBox(height: 15),
// Nama Lengkap Field
TextFormField(
controller: controller.namaLengkapController,
decoration: InputDecoration(
labelText: 'Nama Lengkap',
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validateNamaLengkap,
),
const SizedBox(height: 15),
// Jenis Kelamin Field
DropdownButtonFormField<String>(
decoration: InputDecoration(
labelText: 'Jenis Kelamin',
prefixIcon: const Icon(Icons.people),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
items: const [
DropdownMenuItem(
value: 'LAKI-LAKI',
child: Text('Laki-laki'),
),
DropdownMenuItem(
value: 'PEREMPUAN',
child: Text('Perempuan'),
),
],
onChanged: (value) {
controller.jenisKelaminController.text = value ?? '';
},
validator: controller.validateJenisKelamin,
),
const SizedBox(height: 15),
// No HP Field
TextFormField(
controller: controller.noHpController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'No. HP',
prefixIcon: const Icon(Icons.phone),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 15),
// Alamat Field
TextFormField(
controller: controller.alamatController,
maxLines: 3,
decoration: InputDecoration(
labelText: 'Alamat',
prefixIcon: const Icon(Icons.home),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 15),
// Tempat Lahir Field
TextFormField(
controller: controller.tempatLahirController,
decoration: InputDecoration(
labelText: 'Tempat Lahir',
prefixIcon: const Icon(Icons.location_city),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 15),
// Tanggal Lahir Field
TextFormField(
controller: controller.tanggalLahirController,
keyboardType: TextInputType.datetime,
decoration: InputDecoration(
labelText: 'Tanggal Lahir (DD-MM-YYYY)',
prefixIcon: const Icon(Icons.calendar_today),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
onTap: () async {
FocusScope.of(context).requestFocus(FocusNode());
final DateTime? picked = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
);
if (picked != null) {
controller.tanggalLahirController.text =
'${picked.day.toString().padLeft(2, '0')}-'
'${picked.month.toString().padLeft(2, '0')}-'
'${picked.year}';
}
},
),
const SizedBox(height: 15),
// Agama Field
DropdownButtonFormField<String>(
decoration: InputDecoration(
labelText: 'Agama',
prefixIcon: const Icon(Icons.church),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
items: const [
DropdownMenuItem(
value: 'ISLAM',
child: Text('Islam'),
),
DropdownMenuItem(
value: 'KRISTEN PROTESTAN',
child: Text('Kristen Protestan'),
),
DropdownMenuItem(
value: 'KRISTEN KATOLIK',
child: Text('Kristen Katolik'),
),
DropdownMenuItem(
value: 'HINDU',
child: Text('Hindu'),
),
DropdownMenuItem(
value: 'BUDHA',
child: Text('Budha'),
),
DropdownMenuItem(
value: 'KONGHUCU',
child: Text('Konghucu'),
),
],
onChanged: (value) {
controller.agamaController.text = value ?? '';
},
),
const SizedBox(height: 30),
// Submit Button
Obx(() => ElevatedButton(
onPressed: controller.isLoading.value
? null
: controller.completeWargaProfile,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: controller.isLoading.value
? const SpinKitThreeBounce(
color: Colors.white,
size: 24,
)
: const Text(
'SIMPAN',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
)),
const SizedBox(height: 15),
// Kembali Button
OutlinedButton(
onPressed: () => Get.back(),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: const Text(
'KEMBALI KE DASHBOARD',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
),
),
),
);
}
}

View File

@ -0,0 +1,133 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
import 'package:penyaluran_app/app/routes/app_pages.dart';
class LoginView extends GetView<AuthController> {
const LoginView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: Form(
key: controller.loginFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 50),
// Logo atau Judul
const Center(
child: Text(
'Penyaluran App',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
),
const SizedBox(height: 10),
const Center(
child: Text(
'Masuk ke akun Anda',
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
),
const SizedBox(height: 50),
// Email Field
TextFormField(
controller: controller.emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: const Icon(Icons.email),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validateEmail,
),
const SizedBox(height: 20),
// Password Field
TextFormField(
controller: controller.passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: const Icon(Icons.lock),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validatePassword,
),
const SizedBox(height: 10),
// Forgot Password
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
// Implementasi lupa password
},
child: const Text('Lupa Password?'),
),
),
const SizedBox(height: 20),
// Login Button
Obx(() => ElevatedButton(
onPressed: controller.isLoading.value
? null
: controller.login,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: controller.isLoading.value
? const SpinKitThreeBounce(
color: Colors.white,
size: 24,
)
: const Text(
'MASUK',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
)),
const SizedBox(height: 20),
// Register Link
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Belum punya akun?'),
TextButton(
onPressed: () => Get.toNamed(Routes.REGISTER),
child: const Text('Daftar'),
),
],
),
],
),
),
),
),
),
);
}
}

View File

@ -0,0 +1,140 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
import 'package:penyaluran_app/app/routes/app_pages.dart';
class RegisterView extends GetView<AuthController> {
const RegisterView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Daftar Akun'),
elevation: 0,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: Form(
key: controller.registerFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 20),
// Logo atau Judul
const Center(
child: Text(
'Penyaluran App',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
),
const SizedBox(height: 10),
const Center(
child: Text(
'Buat akun baru',
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
),
const SizedBox(height: 30),
// Email Field
TextFormField(
controller: controller.emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: const Icon(Icons.email),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validateEmail,
),
const SizedBox(height: 20),
// Password Field
TextFormField(
controller: controller.passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: const Icon(Icons.lock),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validatePassword,
),
const SizedBox(height: 20),
// Confirm Password Field
TextFormField(
controller: controller.confirmPasswordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Konfirmasi Password',
prefixIcon: const Icon(Icons.lock_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
validator: controller.validateConfirmPassword,
),
const SizedBox(height: 30),
// Register Button
Obx(() => ElevatedButton(
onPressed: controller.isLoading.value
? null
: controller.register,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: controller.isLoading.value
? const SpinKitThreeBounce(
color: Colors.white,
size: 24,
)
: const Text(
'DAFTAR',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
)),
const SizedBox(height: 20),
// Login Link
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Sudah punya akun?'),
TextButton(
onPressed: () => Get.offAllNamed(Routes.LOGIN),
child: const Text('Masuk'),
),
],
),
],
),
),
),
),
),
);
}
}