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:
81
lib/app/data/models/user_model.dart
Normal file
81
lib/app/data/models/user_model.dart
Normal file
@ -0,0 +1,81 @@
|
||||
class UserModel {
|
||||
final String id;
|
||||
final String email;
|
||||
final String? name;
|
||||
final String? avatar;
|
||||
final String role;
|
||||
final bool isActive;
|
||||
final DateTime? lastLogin;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
UserModel({
|
||||
required this.id,
|
||||
required this.email,
|
||||
this.name,
|
||||
this.avatar,
|
||||
required this.role,
|
||||
this.isActive = true,
|
||||
this.lastLogin,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
id: json['id'],
|
||||
email: json['email'],
|
||||
name: json['name'],
|
||||
avatar: json['avatar'],
|
||||
role: json['role'] ?? 'WARGA',
|
||||
isActive: json['is_active'] ?? true,
|
||||
lastLogin: json['last_login'] != null
|
||||
? DateTime.parse(json['last_login'])
|
||||
: null,
|
||||
createdAt: json['CREATED_AT'] != null
|
||||
? DateTime.parse(json['CREATED_AT'])
|
||||
: null,
|
||||
updatedAt: json['UPDATED_AT'] != null
|
||||
? DateTime.parse(json['UPDATED_AT'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'email': email,
|
||||
'name': name,
|
||||
'avatar': avatar,
|
||||
'role': role,
|
||||
'is_active': isActive,
|
||||
'last_login': lastLogin?.toIso8601String(),
|
||||
'CREATED_AT': createdAt?.toIso8601String(),
|
||||
'UPDATED_AT': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
UserModel copyWith({
|
||||
String? id,
|
||||
String? email,
|
||||
String? name,
|
||||
String? avatar,
|
||||
String? role,
|
||||
bool? isActive,
|
||||
DateTime? lastLogin,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return UserModel(
|
||||
id: id ?? this.id,
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
avatar: avatar ?? this.avatar,
|
||||
role: role ?? this.role,
|
||||
isActive: isActive ?? this.isActive,
|
||||
lastLogin: lastLogin ?? this.lastLogin,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
147
lib/app/data/providers/auth_provider.dart
Normal file
147
lib/app/data/providers/auth_provider.dart
Normal file
@ -0,0 +1,147 @@
|
||||
import 'package:penyaluran_app/app/services/supabase_service.dart';
|
||||
import 'package:penyaluran_app/app/data/models/user_model.dart';
|
||||
|
||||
class AuthProvider {
|
||||
final SupabaseService _supabaseService = SupabaseService.to;
|
||||
|
||||
// Metode untuk mendaftar pengguna baru
|
||||
Future<UserModel?> signUp(String email, String password) async {
|
||||
try {
|
||||
final response = await _supabaseService.signUp(email, password);
|
||||
|
||||
if (response.user != null) {
|
||||
// Tunggu beberapa saat agar trigger di database berjalan
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// Ambil profil pengguna dari database
|
||||
final profileData = await _supabaseService.getUserProfile();
|
||||
|
||||
if (profileData != null) {
|
||||
return UserModel.fromJson({
|
||||
...profileData,
|
||||
'id': response.user!.id,
|
||||
'email': response.user!.email!,
|
||||
});
|
||||
}
|
||||
|
||||
// Jika profil belum tersedia, gunakan data default
|
||||
return UserModel(
|
||||
id: response.user!.id,
|
||||
email: response.user!.email!,
|
||||
role: 'WARGA', // Default role
|
||||
);
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Metode untuk login
|
||||
Future<UserModel?> signIn(String email, String password) async {
|
||||
try {
|
||||
final response = await _supabaseService.signIn(email, password);
|
||||
|
||||
if (response.user != null) {
|
||||
// Ambil profil pengguna dari database
|
||||
final profileData = await _supabaseService.getUserProfile();
|
||||
|
||||
if (profileData != null) {
|
||||
return UserModel.fromJson({
|
||||
...profileData,
|
||||
'id': response.user!.id,
|
||||
'email': response.user!.email!,
|
||||
});
|
||||
}
|
||||
|
||||
// Jika profil belum tersedia, gunakan data default
|
||||
return UserModel(
|
||||
id: response.user!.id,
|
||||
email: response.user!.email!,
|
||||
role: 'WARGA', // Default role
|
||||
);
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Metode untuk logout
|
||||
Future<void> signOut() async {
|
||||
try {
|
||||
await _supabaseService.signOut();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan user saat ini
|
||||
Future<UserModel?> getCurrentUser() async {
|
||||
final user = _supabaseService.currentUser;
|
||||
if (user != null) {
|
||||
// Ambil profil pengguna dari database
|
||||
final profileData = await _supabaseService.getUserProfile();
|
||||
|
||||
if (profileData != null) {
|
||||
return UserModel.fromJson({
|
||||
...profileData,
|
||||
'id': user.id,
|
||||
'email': user.email!,
|
||||
});
|
||||
}
|
||||
|
||||
// Jika profil belum tersedia, gunakan data default
|
||||
return UserModel(
|
||||
id: user.id,
|
||||
email: user.email!,
|
||||
role: 'WARGA', // Default role
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Metode untuk memeriksa apakah user sudah login
|
||||
bool isAuthenticated() {
|
||||
return _supabaseService.isAuthenticated;
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data warga
|
||||
Future<Map<String, dynamic>?> getWargaData() async {
|
||||
return await _supabaseService.getWargaByUserId();
|
||||
}
|
||||
|
||||
// Metode untuk membuat profil warga
|
||||
Future<void> createWargaProfile({
|
||||
required String nik,
|
||||
required String namaLengkap,
|
||||
required String jenisKelamin,
|
||||
String? noHp,
|
||||
String? alamat,
|
||||
String? tempatLahir,
|
||||
DateTime? tanggalLahir,
|
||||
String? agama,
|
||||
}) async {
|
||||
await _supabaseService.createWargaProfile(
|
||||
nik: nik,
|
||||
namaLengkap: namaLengkap,
|
||||
jenisKelamin: jenisKelamin,
|
||||
noHp: noHp,
|
||||
alamat: alamat,
|
||||
tempatLahir: tempatLahir,
|
||||
tanggalLahir: tanggalLahir,
|
||||
agama: agama,
|
||||
);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan notifikasi pengguna
|
||||
Future<List<Map<String, dynamic>>> getUserNotifications(
|
||||
{bool unreadOnly = false}) async {
|
||||
return await _supabaseService.getUserNotifications(unreadOnly: unreadOnly);
|
||||
}
|
||||
|
||||
// Metode untuk menandai notifikasi sebagai telah dibaca
|
||||
Future<void> markNotificationAsRead(int notificationId) async {
|
||||
await _supabaseService.markNotificationAsRead(notificationId);
|
||||
}
|
||||
}
|
11
lib/app/modules/auth/bindings/auth_binding.dart
Normal file
11
lib/app/modules/auth/bindings/auth_binding.dart
Normal 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(),
|
||||
);
|
||||
}
|
||||
}
|
512
lib/app/modules/auth/controllers/auth_controller.dart
Normal file
512
lib/app/modules/auth/controllers/auth_controller.dart
Normal 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);
|
||||
}
|
||||
}
|
270
lib/app/modules/auth/views/complete_profile_view.dart
Normal file
270
lib/app/modules/auth/views/complete_profile_view.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
133
lib/app/modules/auth/views/login_view.dart
Normal file
133
lib/app/modules/auth/views/login_view.dart
Normal 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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
140
lib/app/modules/auth/views/register_view.dart
Normal file
140
lib/app/modules/auth/views/register_view.dart
Normal 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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
11
lib/app/modules/dashboard/bindings/dashboard_binding.dart
Normal file
11
lib/app/modules/dashboard/bindings/dashboard_binding.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/controllers/dashboard_controller.dart';
|
||||
|
||||
class DashboardBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<DashboardController>(
|
||||
() => DashboardController(),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/data/models/user_model.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
|
||||
import 'package:penyaluran_app/app/services/supabase_service.dart';
|
||||
|
||||
class DashboardController extends GetxController {
|
||||
final AuthController _authController = Get.find<AuthController>();
|
||||
final SupabaseService _supabaseService = SupabaseService.to;
|
||||
|
||||
final RxBool isLoading = false.obs;
|
||||
final Rx<Map<String, dynamic>?> roleData = Rx<Map<String, dynamic>?>(null);
|
||||
|
||||
UserModel? get user => _authController.user;
|
||||
String get role => user?.role ?? 'WARGA';
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadRoleData();
|
||||
}
|
||||
|
||||
Future<void> loadRoleData() async {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
if (user != null) {
|
||||
final data = await _supabaseService.getRoleSpecificData(role);
|
||||
roleData.value = data;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error loading role data: $e');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void logout() {
|
||||
_authController.logout();
|
||||
}
|
||||
}
|
229
lib/app/modules/dashboard/views/donatur_dashboard_view.dart
Normal file
229
lib/app/modules/dashboard/views/donatur_dashboard_view.dart
Normal file
@ -0,0 +1,229 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/controllers/dashboard_controller.dart';
|
||||
|
||||
class DonaturDashboardView extends GetView<DashboardController> {
|
||||
const DonaturDashboardView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dashboard Donatur'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: controller.logout,
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Greeting
|
||||
Text(
|
||||
'Halo, ${controller.roleData.value?['namaLengkap'] ?? controller.user?.email ?? 'Donatur'}!',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'Selamat datang di Dashboard Donatur',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Donatur Data
|
||||
if (controller.roleData.value != null) ...[
|
||||
const Text(
|
||||
'Data Donatur',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
'NIK', controller.roleData.value?['NIK'] ?? '-'),
|
||||
_buildInfoRow('Nama',
|
||||
controller.roleData.value?['namaLengkap'] ?? '-'),
|
||||
_buildInfoRow('No. Telp',
|
||||
controller.roleData.value?['noTelp'] ?? '-'),
|
||||
_buildInfoRow('Email',
|
||||
controller.roleData.value?['email'] ?? '-'),
|
||||
_buildInfoRow(
|
||||
'Alamat',
|
||||
controller.roleData.value?['alamatLengkap'] ??
|
||||
'-'),
|
||||
_buildInfoRow('Desa',
|
||||
controller.roleData.value?['namaDesa'] ?? '-'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const Center(
|
||||
child: Text(
|
||||
'Data donatur belum tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Menu
|
||||
const Text(
|
||||
'Menu',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Penitipan Bantuan',
|
||||
'Titipkan bantuan Anda',
|
||||
Icons.card_giftcard,
|
||||
Colors.blue,
|
||||
() {
|
||||
// Navigasi ke halaman penitipan bantuan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Riwayat Penitipan',
|
||||
'Lihat riwayat penitipan bantuan',
|
||||
Icons.history,
|
||||
Colors.green,
|
||||
() {
|
||||
// Navigasi ke halaman riwayat penitipan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Laporan Penyaluran',
|
||||
'Lihat laporan penyaluran bantuan',
|
||||
Icons.assessment,
|
||||
Colors.orange,
|
||||
() {
|
||||
// Navigasi ke halaman laporan penyaluran
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// Navigasi ke halaman penitipan bantuan baru
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
tooltip: 'Titipkan Bantuan Baru',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuCard(String title, String subtitle, IconData icon,
|
||||
Color color, VoidCallback onTap) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
220
lib/app/modules/dashboard/views/petugas_desa_dashboard_view.dart
Normal file
220
lib/app/modules/dashboard/views/petugas_desa_dashboard_view.dart
Normal file
@ -0,0 +1,220 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/controllers/dashboard_controller.dart';
|
||||
|
||||
class PetugasDesaDashboardView extends GetView<DashboardController> {
|
||||
const PetugasDesaDashboardView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dashboard Petugas Desa'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: controller.logout,
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Greeting
|
||||
Text(
|
||||
'Halo, ${controller.roleData.value?['namaLengkap'] ?? controller.user?.email ?? 'Petugas'}!',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'Selamat datang di Dashboard Petugas Desa ${controller.roleData.value?['Desa'] ?? ''}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Petugas Data
|
||||
if (controller.roleData.value != null) ...[
|
||||
const Text(
|
||||
'Data Petugas',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
'NIP', controller.roleData.value?['NIP'] ?? '-'),
|
||||
_buildInfoRow('Nama',
|
||||
controller.roleData.value?['namaLengkap'] ?? '-'),
|
||||
_buildInfoRow('Jabatan',
|
||||
controller.roleData.value?['jabatan'] ?? '-'),
|
||||
_buildInfoRow('Desa',
|
||||
controller.roleData.value?['Desa'] ?? '-'),
|
||||
_buildInfoRow('No. HP',
|
||||
controller.roleData.value?['noHP'] ?? '-'),
|
||||
_buildInfoRow('Email',
|
||||
controller.roleData.value?['email'] ?? '-'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const Center(
|
||||
child: Text(
|
||||
'Data petugas belum tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Menu
|
||||
const Text(
|
||||
'Menu',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Penyaluran Bantuan',
|
||||
'Kelola penyaluran bantuan',
|
||||
Icons.local_shipping,
|
||||
Colors.blue,
|
||||
() {
|
||||
// Navigasi ke halaman penyaluran bantuan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Pengaduan',
|
||||
'Kelola pengaduan warga',
|
||||
Icons.report_problem,
|
||||
Colors.orange,
|
||||
() {
|
||||
// Navigasi ke halaman pengaduan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Laporan',
|
||||
'Lihat laporan penyaluran',
|
||||
Icons.assessment,
|
||||
Colors.green,
|
||||
() {
|
||||
// Navigasi ke halaman laporan
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuCard(String title, String subtitle, IconData icon,
|
||||
Color color, VoidCallback onTap) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/controllers/dashboard_controller.dart';
|
||||
|
||||
class PetugasVerifikasiDashboardView extends GetView<DashboardController> {
|
||||
const PetugasVerifikasiDashboardView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dashboard Petugas Verifikasi'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: controller.logout,
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Greeting
|
||||
Text(
|
||||
'Halo, ${controller.roleData.value?['namaLengkap'] ?? controller.user?.email ?? 'Petugas'}!',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'Selamat datang di Dashboard Petugas Verifikasi',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Petugas Data
|
||||
if (controller.roleData.value != null) ...[
|
||||
const Text(
|
||||
'Data Petugas',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
'NIP', controller.roleData.value?['nip'] ?? '-'),
|
||||
_buildInfoRow('Nama',
|
||||
controller.roleData.value?['namaLengkap'] ?? '-'),
|
||||
_buildInfoRow('Jabatan',
|
||||
controller.roleData.value?['jabatan'] ?? '-'),
|
||||
_buildInfoRow('Email',
|
||||
controller.roleData.value?['email'] ?? '-'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const Center(
|
||||
child: Text(
|
||||
'Data petugas belum tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Menu
|
||||
const Text(
|
||||
'Menu',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Verifikasi Data Warga',
|
||||
'Verifikasi data warga baru',
|
||||
Icons.verified_user,
|
||||
Colors.blue,
|
||||
() {
|
||||
// Navigasi ke halaman verifikasi data warga
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Verifikasi Pengajuan Bantuan',
|
||||
'Verifikasi pengajuan bantuan',
|
||||
Icons.fact_check,
|
||||
Colors.green,
|
||||
() {
|
||||
// Navigasi ke halaman verifikasi pengajuan bantuan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Kelola Skema Bantuan',
|
||||
'Kelola skema bantuan yang tersedia',
|
||||
Icons.settings,
|
||||
Colors.orange,
|
||||
() {
|
||||
// Navigasi ke halaman kelola skema bantuan
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuCard(String title, String subtitle, IconData icon,
|
||||
Color color, VoidCallback onTap) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
303
lib/app/modules/dashboard/views/warga_dashboard_view.dart
Normal file
303
lib/app/modules/dashboard/views/warga_dashboard_view.dart
Normal file
@ -0,0 +1,303 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/controllers/dashboard_controller.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
|
||||
|
||||
class WargaDashboardView extends GetView<DashboardController> {
|
||||
const WargaDashboardView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authController = Get.find<AuthController>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dashboard Warga'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: controller.logout,
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Greeting
|
||||
Text(
|
||||
'Halo, ${controller.user?.email ?? 'Pengguna'}!',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'Selamat datang di Dashboard Warga',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Status Profil
|
||||
Obx(() => authController.isWargaProfileComplete.value
|
||||
? _buildProfileCompleteCard()
|
||||
: _buildProfileIncompleteCard(authController)),
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Warga Data
|
||||
if (controller.roleData.value != null) ...[
|
||||
const Text(
|
||||
'Data Pribadi',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoRow('NIK',
|
||||
controller.roleData.value?['NIK'] ?? '-'),
|
||||
_buildInfoRow(
|
||||
'Nama',
|
||||
controller.roleData.value?['namaLengkap'] ??
|
||||
'-'),
|
||||
_buildInfoRow(
|
||||
'Jenis Kelamin',
|
||||
controller.roleData.value?['jenisKelamin'] ??
|
||||
'-'),
|
||||
_buildInfoRow('No. HP',
|
||||
controller.roleData.value?['noHp'] ?? '-'),
|
||||
_buildInfoRow('Alamat',
|
||||
controller.roleData.value?['alamat'] ?? '-'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const Center(
|
||||
child: Text(
|
||||
'Data warga belum tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Menu
|
||||
const Text(
|
||||
'Menu',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Pengajuan Bantuan',
|
||||
'Ajukan permohonan bantuan',
|
||||
Icons.request_page,
|
||||
Colors.blue,
|
||||
() {
|
||||
// Navigasi ke halaman pengajuan bantuan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Pengaduan',
|
||||
'Sampaikan pengaduan Anda',
|
||||
Icons.report_problem,
|
||||
Colors.orange,
|
||||
() {
|
||||
// Navigasi ke halaman pengaduan
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMenuCard(
|
||||
'Status Bantuan',
|
||||
'Lihat status bantuan Anda',
|
||||
Icons.info,
|
||||
Colors.green,
|
||||
() {
|
||||
// Navigasi ke halaman status bantuan
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget untuk menampilkan status profil lengkap
|
||||
Widget _buildProfileCompleteCard() {
|
||||
return Card(
|
||||
color: Colors.green.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.check_circle, color: Colors.green.shade700),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Profil Anda sudah lengkap',
|
||||
style: TextStyle(
|
||||
color: Colors.green,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget untuk menampilkan status profil belum lengkap dengan tombol
|
||||
Widget _buildProfileIncompleteCard(AuthController authController) {
|
||||
return Card(
|
||||
color: Colors.orange.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.orange.shade700),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Profil Anda belum lengkap',
|
||||
style: TextStyle(
|
||||
color: Colors.orange,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'Lengkapi profil Anda untuk mengakses semua fitur aplikasi',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: authController.navigateToCompleteProfile,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.orange,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Lengkapi Profil'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuCard(String title, String subtitle, IconData icon,
|
||||
Color color, VoidCallback onTap) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
11
lib/app/modules/home/bindings/home_binding.dart
Normal file
11
lib/app/modules/home/bindings/home_binding.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/home/controllers/home_controller.dart';
|
||||
|
||||
class HomeBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<HomeController>(
|
||||
() => HomeController(),
|
||||
);
|
||||
}
|
||||
}
|
14
lib/app/modules/home/controllers/home_controller.dart
Normal file
14
lib/app/modules/home/controllers/home_controller.dart
Normal file
@ -0,0 +1,14 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/controllers/auth_controller.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final AuthController _authController = Get.find<AuthController>();
|
||||
|
||||
// Getter untuk mendapatkan user dari auth controller
|
||||
get user => _authController.user;
|
||||
|
||||
// Metode untuk logout
|
||||
void logout() {
|
||||
_authController.logout();
|
||||
}
|
||||
}
|
63
lib/app/modules/home/views/home_view.dart
Normal file
63
lib/app/modules/home/views/home_view.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/home/controllers/home_controller.dart';
|
||||
|
||||
class HomeView extends GetView<HomeController> {
|
||||
const HomeView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Penyaluran App'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: controller.logout,
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Greeting
|
||||
Text(
|
||||
'Halo, ${controller.user?.email ?? 'Pengguna'}!',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'Selamat datang di Penyaluran App',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Dashboard Content
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Halaman Dashboard',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
63
lib/app/routes/app_pages.dart
Normal file
63
lib/app/routes/app_pages.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/views/login_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/views/register_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/views/complete_profile_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/home/views/home_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/views/warga_dashboard_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/views/petugas_verifikasi_dashboard_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/views/petugas_desa_dashboard_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/views/donatur_dashboard_view.dart';
|
||||
import 'package:penyaluran_app/app/modules/auth/bindings/auth_binding.dart';
|
||||
import 'package:penyaluran_app/app/modules/home/bindings/home_binding.dart';
|
||||
import 'package:penyaluran_app/app/modules/dashboard/bindings/dashboard_binding.dart';
|
||||
|
||||
part 'app_routes.dart';
|
||||
|
||||
class AppPages {
|
||||
AppPages._();
|
||||
|
||||
static const INITIAL = Routes.LOGIN;
|
||||
|
||||
static final routes = [
|
||||
GetPage(
|
||||
name: _Paths.HOME,
|
||||
page: () => const HomeView(),
|
||||
binding: HomeBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.LOGIN,
|
||||
page: () => const LoginView(),
|
||||
binding: AuthBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.REGISTER,
|
||||
page: () => const RegisterView(),
|
||||
binding: AuthBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.COMPLETE_PROFILE,
|
||||
page: () => const CompleteProfileView(),
|
||||
binding: AuthBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.WARGA_DASHBOARD,
|
||||
page: () => const WargaDashboardView(),
|
||||
binding: DashboardBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.PETUGAS_VERIFIKASI_DASHBOARD,
|
||||
page: () => const PetugasVerifikasiDashboardView(),
|
||||
binding: DashboardBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.PETUGAS_DESA_DASHBOARD,
|
||||
page: () => const PetugasDesaDashboardView(),
|
||||
binding: DashboardBinding(),
|
||||
),
|
||||
GetPage(
|
||||
name: _Paths.DONATUR_DASHBOARD,
|
||||
page: () => const DonaturDashboardView(),
|
||||
binding: DashboardBinding(),
|
||||
),
|
||||
];
|
||||
}
|
26
lib/app/routes/app_routes.dart
Normal file
26
lib/app/routes/app_routes.dart
Normal file
@ -0,0 +1,26 @@
|
||||
part of 'app_pages.dart';
|
||||
|
||||
abstract class Routes {
|
||||
Routes._();
|
||||
static const HOME = _Paths.HOME;
|
||||
static const LOGIN = _Paths.LOGIN;
|
||||
static const REGISTER = _Paths.REGISTER;
|
||||
static const COMPLETE_PROFILE = _Paths.COMPLETE_PROFILE;
|
||||
static const WARGA_DASHBOARD = _Paths.WARGA_DASHBOARD;
|
||||
static const PETUGAS_VERIFIKASI_DASHBOARD =
|
||||
_Paths.PETUGAS_VERIFIKASI_DASHBOARD;
|
||||
static const PETUGAS_DESA_DASHBOARD = _Paths.PETUGAS_DESA_DASHBOARD;
|
||||
static const DONATUR_DASHBOARD = _Paths.DONATUR_DASHBOARD;
|
||||
}
|
||||
|
||||
abstract class _Paths {
|
||||
_Paths._();
|
||||
static const HOME = '/home';
|
||||
static const LOGIN = '/login';
|
||||
static const REGISTER = '/register';
|
||||
static const COMPLETE_PROFILE = '/complete-profile';
|
||||
static const WARGA_DASHBOARD = '/warga-dashboard';
|
||||
static const PETUGAS_VERIFIKASI_DASHBOARD = '/petugas-verifikasi-dashboard';
|
||||
static const PETUGAS_DESA_DASHBOARD = '/petugas-desa-dashboard';
|
||||
static const DONATUR_DASHBOARD = '/donatur-dashboard';
|
||||
}
|
268
lib/app/services/supabase_service.dart
Normal file
268
lib/app/services/supabase_service.dart
Normal file
@ -0,0 +1,268 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class SupabaseService extends GetxService {
|
||||
static SupabaseService get to => Get.find<SupabaseService>();
|
||||
|
||||
late final SupabaseClient client;
|
||||
|
||||
// Ganti dengan URL dan API key Supabase Anda
|
||||
static const String supabaseUrl = String.fromEnvironment('SUPABASE_URL',
|
||||
defaultValue: 'http://labulabs.net:8000');
|
||||
static const String supabaseKey = String.fromEnvironment('SUPABASE_KEY',
|
||||
defaultValue:
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogImFub24iLAogICJpc3MiOiAic3VwYWJhc2UiLAogICJpYXQiOiAxNzMxODYyODAwLAogICJleHAiOiAxODg5NjI5MjAwCn0.4IpwhwCVbfYXxb8JlZOLSBzCt6kQmypkvuso7N8Aicc');
|
||||
|
||||
Future<SupabaseService> init() async {
|
||||
await Supabase.initialize(
|
||||
url: supabaseUrl,
|
||||
anonKey: supabaseKey,
|
||||
);
|
||||
|
||||
client = Supabase.instance.client;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Metode untuk mendaftar pengguna baru
|
||||
Future<AuthResponse> signUp(String email, String password) async {
|
||||
return await client.auth.signUp(
|
||||
email: email,
|
||||
password: password,
|
||||
data: {'autoconfirm': true},
|
||||
);
|
||||
}
|
||||
|
||||
// Metode untuk login
|
||||
Future<AuthResponse> signIn(String email, String password) async {
|
||||
return await client.auth.signInWithPassword(
|
||||
email: email,
|
||||
password: password,
|
||||
);
|
||||
}
|
||||
|
||||
// Metode untuk logout
|
||||
Future<void> signOut() async {
|
||||
await client.auth.signOut();
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan user saat ini
|
||||
User? get currentUser => client.auth.currentUser;
|
||||
|
||||
// Metode untuk memeriksa apakah user sudah login
|
||||
bool get isAuthenticated => currentUser != null;
|
||||
|
||||
// Metode untuk mendapatkan profil pengguna
|
||||
Future<Map<String, dynamic>?> getUserProfile() async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
final response = await client
|
||||
.from('user_profile')
|
||||
.select()
|
||||
.eq('id', currentUser!.id)
|
||||
.maybeSingle();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan role pengguna
|
||||
Future<String?> getUserRole() async {
|
||||
final profile = await getUserProfile();
|
||||
return profile?['role'];
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data berdasarkan peran
|
||||
Future<Map<String, dynamic>?> getRoleSpecificData(String role) async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
switch (role) {
|
||||
case 'WARGA':
|
||||
return await getWargaByUserId();
|
||||
case 'PETUGASVERIFIKASI':
|
||||
return await getPetugasVerifikasiData();
|
||||
case 'PETUGASDESA':
|
||||
return await getPetugasDesaData();
|
||||
case 'DONATUR':
|
||||
return await getDonaturData();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data petugas verifikasi
|
||||
Future<Map<String, dynamic>?> getPetugasVerifikasiData() async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
final response = await client
|
||||
.from('xx02_PetugasVerifikasi')
|
||||
.select()
|
||||
.eq('userId', currentUser!.id)
|
||||
.maybeSingle();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data petugas desa
|
||||
Future<Map<String, dynamic>?> getPetugasDesaData() async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
final response = await client
|
||||
.from('xx01_PetugasDesa')
|
||||
.select()
|
||||
.eq('userId', currentUser!.id)
|
||||
.maybeSingle();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data donatur
|
||||
Future<Map<String, dynamic>?> getDonaturData() async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
final response = await client
|
||||
.from('xx01_Donatur')
|
||||
.select()
|
||||
.eq('userId', currentUser!.id)
|
||||
.maybeSingle();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// Metode untuk membuat data warga
|
||||
Future<void> createWargaProfile({
|
||||
required String nik,
|
||||
required String namaLengkap,
|
||||
required String jenisKelamin,
|
||||
String? noHp,
|
||||
String? alamat,
|
||||
String? tempatLahir,
|
||||
DateTime? tanggalLahir,
|
||||
String? agama,
|
||||
}) async {
|
||||
if (currentUser == null) return;
|
||||
|
||||
await client.from('xx02_Warga').insert({
|
||||
'NIK': nik,
|
||||
'namaLengkap': namaLengkap,
|
||||
'jenisKelamin': jenisKelamin,
|
||||
'noHp': noHp,
|
||||
'alamat': alamat,
|
||||
'tempatLahir': tempatLahir,
|
||||
'tanggalLahir': tanggalLahir?.toIso8601String(),
|
||||
'agama': agama,
|
||||
'userId': currentUser!.id,
|
||||
'email': currentUser!.email,
|
||||
});
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data warga berdasarkan userId
|
||||
Future<Map<String, dynamic>?> getWargaByUserId() async {
|
||||
if (currentUser == null) return null;
|
||||
|
||||
final response = await client
|
||||
.from('xx02_Warga')
|
||||
.select()
|
||||
.eq('userId', currentUser!.id)
|
||||
.maybeSingle();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan notifikasi pengguna
|
||||
Future<List<Map<String, dynamic>>> getUserNotifications(
|
||||
{bool unreadOnly = false}) async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final query = client.from('Notification').select();
|
||||
|
||||
// Tambahkan filter untuk user ID
|
||||
final filteredQuery = query.eq('userId', currentUser!.id);
|
||||
|
||||
// Tambahkan filter untuk notifikasi yang belum dibaca jika diperlukan
|
||||
final finalQuery =
|
||||
unreadOnly ? filteredQuery.eq('isRead', false) : filteredQuery;
|
||||
|
||||
// Tambahkan pengurutan
|
||||
final response = await finalQuery.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk menandai notifikasi sebagai telah dibaca
|
||||
Future<void> markNotificationAsRead(int notificationId) async {
|
||||
await client
|
||||
.from('Notification')
|
||||
.update({'isRead': true}).eq('notificationId', notificationId);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data verifikasi warga
|
||||
Future<List<Map<String, dynamic>>> getVerifikasiDataWarga() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx02_VerifikasiDataWarga')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data pengajuan bantuan
|
||||
Future<List<Map<String, dynamic>>> getPengajuanBantuan() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx02_PengajuanKelayakanBantuan')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data skema bantuan
|
||||
Future<List<Map<String, dynamic>>> getSkemaBantuan() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx02_SkemaBantuan')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data penyaluran bantuan
|
||||
Future<List<Map<String, dynamic>>> getPenyaluranBantuan() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx01_PenyaluranBantuan')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data penitipan bantuan
|
||||
Future<List<Map<String, dynamic>>> getPenitipanBantuan() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx01_PenitipanBantuan')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
|
||||
// Metode untuk mendapatkan data pengaduan
|
||||
Future<List<Map<String, dynamic>>> getPengaduan() async {
|
||||
if (currentUser == null) return [];
|
||||
|
||||
final response = await client
|
||||
.from('xx01_Pengaduan')
|
||||
.select()
|
||||
.order('CREATED_AT', ascending: false);
|
||||
|
||||
return List<Map<String, dynamic>>.from(response);
|
||||
}
|
||||
}
|
129
lib/main.dart
129
lib/main.dart
@ -1,125 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:penyaluran_app/app/routes/app_pages.dart';
|
||||
import 'package:penyaluran_app/app/services/supabase_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Inisialisasi Supabase
|
||||
await initServices();
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
// Inisialisasi service
|
||||
Future<void> initServices() async {
|
||||
await Get.putAsync(() => SupabaseService().init());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
return GetMaterialApp(
|
||||
title: 'Penyaluran App',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
debugShowCheckedModeBanner: false,
|
||||
initialRoute: AppPages.INITIAL,
|
||||
getPages: AppPages.routes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user