membuat tampilan lebih menarik

This commit is contained in:
Khafidh Fuadi
2025-03-27 22:31:14 +07:00
parent f6d3eef2cf
commit c008020705
44 changed files with 6260 additions and 3195 deletions

View File

@ -24,6 +24,9 @@ class DonaturDashboardController extends GetxController {
// Indeks tab yang aktif di bottom navigation bar
final RxInt activeTabIndex = 0.obs;
// Menyimpan ID skema bantuan yang dipilih
final RxString selectedSkemaBantuanId = ''.obs;
// Data untuk skema bantuan tersedia
final RxList<SkemaBantuanModel> skemaBantuan = <SkemaBantuanModel>[].obs;
@ -228,7 +231,8 @@ class DonaturDashboardController extends GetxController {
final now = DateTime.now();
final response = await _supabaseService.client
.from('penyaluran_bantuan')
.select()
.select(
'*, lokasi_penyaluran:lokasi_penyaluran_id(*), kategori:kategori_bantuan_id(*), petugas:petugas_id(*)')
.order('tanggal_penyaluran', ascending: true);
// Konversi ke model lalu filter di sisi client
@ -459,4 +463,25 @@ class DonaturDashboardController extends GetxController {
isLoading.value = false;
}
}
// Mendapatkan nama lokasi penyaluran berdasarkan ID
Future<String?> getLokasiPenyaluran(String? lokasiId) async {
if (lokasiId == null) return null;
try {
final response = await _supabaseService.client
.from('lokasi_penyaluran')
.select('nama')
.eq('id', lokasiId)
.single();
if (response != null && response['nama'] != null) {
return response['nama'] as String;
}
return null;
} catch (e) {
print('Error fetching lokasi penyaluran: $e');
return null;
}
}
}

View File

@ -0,0 +1,578 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:penyaluran_app/app/modules/donatur/controllers/donatur_dashboard_controller.dart';
import 'package:penyaluran_app/app/data/models/penyaluran_bantuan_model.dart';
import 'package:penyaluran_app/app/widgets/section_header.dart';
class DonaturJadwalDetailView extends GetView<DonaturDashboardController> {
const DonaturJadwalDetailView({Key? key}) : super(key: key);
@override
DonaturDashboardController get controller {
if (!Get.isRegistered<DonaturDashboardController>(
tag: 'donatur_dashboard')) {
return Get.put(DonaturDashboardController(),
tag: 'donatur_dashboard', permanent: true);
}
return Get.find<DonaturDashboardController>(tag: 'donatur_dashboard');
}
@override
Widget build(BuildContext context) {
final jadwal = Get.arguments as PenyaluranBantuanModel;
return Scaffold(
appBar: AppBar(
title: const Text('Detail Jadwal Penyaluran'),
elevation: 0,
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeaderSection(jadwal),
_buildDetailSection(jadwal),
_buildPelaksanaSection(jadwal),
_buildStatusSection(jadwal),
_buildActionSection(jadwal),
],
),
),
);
}
Widget _buildHeaderSection(PenyaluranBantuanModel jadwal) {
String statusText = 'Akan Datang';
Color statusColor = Colors.blue;
switch (jadwal.status) {
case 'SELESAI':
statusText = 'Selesai';
statusColor = Colors.green;
break;
case 'DIBATALKAN':
statusText = 'Dibatalkan';
statusColor = Colors.red;
break;
case 'DALAM_PROSES':
statusText = 'Dalam Proses';
statusColor = Colors.orange;
break;
default:
statusText = 'Akan Datang';
statusColor = Colors.blue;
}
return Container(
width: double.infinity,
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
statusColor.withOpacity(0.8),
statusColor.withOpacity(0.5),
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_getStatusIcon(jadwal.status),
size: 16,
color: statusColor,
),
const SizedBox(width: 6),
Text(
statusText,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: statusColor,
),
),
],
),
),
const SizedBox(height: 12),
Text(
jadwal.nama ?? 'Penyaluran Bantuan',
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 8),
if (jadwal.tanggalPenyaluran != null)
Row(
children: [
const Icon(
Icons.calendar_today,
size: 16,
color: Colors.white,
),
const SizedBox(width: 8),
Text(
DateFormat('EEEE, dd MMMM yyyy', 'id_ID')
.format(jadwal.tanggalPenyaluran!),
style: const TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
],
),
],
),
);
}
Widget _buildDetailSection(PenyaluranBantuanModel jadwal) {
return Container(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SectionHeader(title: 'Informasi Penyaluran'),
const SizedBox(height: 16),
_buildInfoItem(
icon: Icons.description_outlined,
title: 'Deskripsi',
value: jadwal.deskripsi ?? 'Tidak ada deskripsi',
),
const SizedBox(height: 12),
_buildInfoItem(
icon: Icons.people_outline,
title: 'Jumlah Penerima',
value: jadwal.jumlahPenerima != null
? '${jadwal.jumlahPenerima} orang'
: 'Belum ditentukan',
),
const SizedBox(height: 12),
_buildInfoItem(
icon: Icons.category_outlined,
title: 'Kategori Bantuan',
value: jadwal.kategoriNama ?? jadwal.kategoriBantuanId ?? 'Umum',
),
const SizedBox(height: 12),
_buildInfoItem(
icon: Icons.location_on_outlined,
title: 'Lokasi Penyaluran',
value: jadwal.lokasiNama ??
jadwal.lokasiPenyaluranId ??
'Belum ditentukan',
),
],
),
);
}
Widget _buildPelaksanaSection(PenyaluranBantuanModel jadwal) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SectionHeader(title: 'Informasi Pelaksana'),
const SizedBox(height: 16),
Card(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(color: Colors.grey.shade300),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Row(
children: [
CircleAvatar(
radius: 25,
backgroundColor: Colors.blue.shade100,
child: Icon(
Icons.person,
color: Colors.blue.shade700,
size: 30,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Petugas Pelaksana',
style: TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
const SizedBox(height: 4),
Text(
jadwal.namaPetugas ??
jadwal.petugasId ??
'Belum ditugaskan',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
],
),
),
),
],
),
);
}
Widget _buildStatusSection(PenyaluranBantuanModel jadwal) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SectionHeader(title: 'Status Penyaluran'),
const SizedBox(height: 16),
_buildStatusTimeline(jadwal),
],
),
);
}
Widget _buildStatusTimeline(PenyaluranBantuanModel jadwal) {
final status = jadwal.status;
final bool isCompleted = status == 'SELESAI';
final bool isCancelled = status == 'DIBATALKAN';
final bool isInProgress = status == 'DALAM_PROSES';
return Column(
children: [
_buildTimelineItem(
title: 'Dijadwalkan',
date: jadwal.createdAt != null
? DateFormat('dd MMM yyyy', 'id_ID').format(jadwal.createdAt!)
: '-',
isCompleted: true,
isFirst: true,
),
_buildTimelineItem(
title: 'Dalam Proses',
date: isInProgress || isCompleted
? jadwal.tanggalPenyaluran != null
? DateFormat('dd MMM yyyy', 'id_ID')
.format(jadwal.tanggalPenyaluran!)
: '-'
: '-',
isCompleted: isInProgress || isCompleted,
isCancelled: isCancelled,
),
_buildTimelineItem(
title: 'Selesai',
date: isCompleted
? jadwal.tanggalSelesai != null
? DateFormat('dd MMM yyyy', 'id_ID')
.format(jadwal.tanggalSelesai!)
: '-'
: '-',
isCompleted: isCompleted,
isCancelled: isCancelled,
isLast: true,
),
if (isCancelled) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.red.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.red.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.cancel, color: Colors.red.shade700, size: 20),
const SizedBox(width: 8),
Text(
'Penyaluran Dibatalkan',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.red.shade700,
),
),
],
),
const SizedBox(height: 8),
Text(
'Alasan pembatalan: ${jadwal.alasanPembatalan ?? 'Tidak ada alasan yang diberikan'}',
style: TextStyle(color: Colors.red.shade700),
),
const SizedBox(height: 8),
if (jadwal.tanggalPembatalan != null)
Text(
'Dibatalkan pada: ${DateFormat('dd MMMM yyyy', 'id_ID').format(jadwal.tanggalPembatalan!)}',
style: TextStyle(
fontSize: 14,
color: Colors.red.shade700,
),
),
],
),
),
],
],
);
}
Widget _buildTimelineItem({
required String title,
required String date,
required bool isCompleted,
bool isFirst = false,
bool isLast = false,
bool isCancelled = false,
}) {
return Row(
children: [
SizedBox(
width: 20,
child: Column(
children: [
if (!isFirst)
Container(
width: 2,
height: 20,
color: isCompleted
? Colors.green
: isCancelled
? Colors.red
: Colors.grey.shade300,
),
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isCompleted
? Colors.green
: isCancelled
? Colors.red
: Colors.grey.shade300,
border: Border.all(
color: isCompleted
? Colors.green
: isCancelled
? Colors.red
: Colors.grey.shade300,
width: 2,
),
),
child: isCompleted
? const Icon(Icons.check, size: 12, color: Colors.white)
: isCancelled
? const Icon(Icons.close, size: 12, color: Colors.white)
: null,
),
if (!isLast)
Container(
width: 2,
height: 20,
color: isCompleted && !isCancelled
? Colors.green
: Colors.grey.shade300,
),
],
),
),
const SizedBox(width: 12),
Expanded(
child: Container(
margin: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isCompleted
? Colors.black
: isCancelled
? Colors.red
: Colors.grey,
),
),
Text(
date,
style: TextStyle(
fontSize: 14,
color: isCompleted
? Colors.grey.shade700
: isCancelled
? Colors.red.shade300
: Colors.grey.shade400,
),
),
],
),
),
),
],
);
}
Widget _buildActionSection(PenyaluranBantuanModel jadwal) {
if (jadwal.status == 'DIBATALKAN') {
return const SizedBox.shrink();
}
return Container(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SectionHeader(title: 'Tindakan'),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () => _hubungiPetugas(jadwal),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 12),
backgroundColor: Colors.green,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
icon: const Icon(Icons.chat_outlined),
label: const Text('Hubungi Petugas'),
),
),
if (jadwal.status == 'SELESAI') ...[
const SizedBox(width: 12),
Expanded(
child: OutlinedButton.icon(
onPressed: () => _lihatLaporan(jadwal),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 12),
foregroundColor: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
icon: const Icon(Icons.description_outlined),
label: const Text('Lihat Laporan'),
),
),
],
],
),
],
),
);
}
Widget _buildInfoItem({
required IconData icon,
required String title,
required String value,
}) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(8),
),
child: Icon(
icon,
size: 20,
color: Colors.blue.shade700,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade600,
),
),
const SizedBox(height: 4),
Text(
value,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
);
}
IconData _getStatusIcon(String? status) {
switch (status) {
case 'SELESAI':
return Icons.check_circle;
case 'DIBATALKAN':
return Icons.cancel;
case 'DALAM_PROSES':
return Icons.timelapse;
default:
return Icons.event_available;
}
}
void _hubungiPetugas(PenyaluranBantuanModel jadwal) {
// Implementasi untuk menghubungi petugas
Get.snackbar(
'Fitur Belum Tersedia',
'Fitur untuk menghubungi petugas akan segera hadir',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.blue.withOpacity(0.9),
colorText: Colors.white,
);
}
void _lihatLaporan(PenyaluranBantuanModel jadwal) {
// Navigasi ke halaman laporan
Get.toNamed('/donatur/laporan/${jadwal.id}', arguments: jadwal);
}
}

View File

@ -183,140 +183,294 @@ class DonaturJadwalView extends GetView<DonaturDashboardController> {
statusColor = Colors.blue;
}
return Container(
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 5),
),
],
),
child: Card(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
return GestureDetector(
onTap: () => _navigateToDetail(jadwal),
child: Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.06),
blurRadius: 12,
offset: const Offset(0, 6),
),
],
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 50,
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: statusColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(10),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (jadwal.tanggalPenyaluran != null) ...[
Text(
DateFormat('dd').format(jadwal.tanggalPenyaluran!),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: statusColor,
),
),
Text(
DateFormat('MMM', 'id_ID')
.format(jadwal.tanggalPenyaluran!)
.toUpperCase(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: statusColor,
),
),
] else
Icon(
Icons.event,
color: statusColor,
size: 24,
),
],
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
jadwal.nama ?? 'Penyaluran Bantuan',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
child: Card(
elevation: 0,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(
color: statusColor.withOpacity(0.3),
width: 1.5,
),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Tanggal dalam badge khusus
Container(
width: 58,
height: 65,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: statusColor.withOpacity(0.2),
blurRadius: 8,
offset: const Offset(0, 3),
)
],
border: Border.all(
color: statusColor.withOpacity(0.5),
width: 1.5,
),
const SizedBox(height: 4),
Row(
children: [
Icon(
Icons.calendar_today,
size: 14,
color: Colors.grey.shade600,
),
const SizedBox(width: 4),
Text(
formattedDate,
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade700,
),
child: Column(
children: [
// Header badge
Container(
padding: const EdgeInsets.symmetric(vertical: 3),
width: double.infinity,
decoration: BoxDecoration(
color: statusColor,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(10),
),
),
],
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: statusColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
statusText,
style: TextStyle(
fontSize: 12,
color: statusColor,
fontWeight: FontWeight.bold,
child: Text(
jadwal.tanggalPenyaluran != null
? DateFormat('MMM', 'id_ID')
.format(jadwal.tanggalPenyaluran!)
.toUpperCase()
: 'TBD',
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
),
],
// Tanggal
Expanded(
child: Center(
child: Text(
jadwal.tanggalPenyaluran != null
? DateFormat('dd')
.format(jadwal.tanggalPenyaluran!)
: '-',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: statusColor,
),
),
),
),
],
),
),
const SizedBox(width: 16),
// Informasi utama
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
jadwal.nama ?? 'Penyaluran Bantuan',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 6),
Row(
children: [
Icon(
Icons.calendar_today,
size: 14,
color: Colors.grey.shade600,
),
const SizedBox(width: 6),
Expanded(
child: Text(
formattedDate,
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade700,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 4),
if (jadwal.lokasiPenyaluranId != null) ...[
Row(
children: [
Icon(
Icons.location_on_outlined,
size: 14,
color: Colors.grey.shade600,
),
const SizedBox(width: 6),
Expanded(
child: Text(
jadwal.lokasiNama ??
jadwal.lokasiPenyaluranId!,
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade700,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 4),
],
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: statusColor.withOpacity(0.15),
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_getStatusIcon(jadwal.status),
size: 14,
color: statusColor,
),
const SizedBox(width: 4),
Text(
statusText,
style: TextStyle(
fontSize: 12,
color: statusColor,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
),
],
),
if (jadwal.deskripsi != null &&
jadwal.deskripsi!.isNotEmpty) ...[
const Divider(height: 24),
Text(
jadwal.deskripsi!,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
if (jadwal.deskripsi != null && jadwal.deskripsi!.isNotEmpty) ...[
const Divider(height: 24),
Text(
jadwal.deskripsi!,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
// Footer dengan informasi bantuan dan tombol detail
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Informasi bantuan yang diberikan
if (jadwal.jumlahBantuan != null) ...[
Row(
children: [
Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
shape: BoxShape.circle,
),
child: const Icon(
Icons.volunteer_activism,
size: 14,
color: Colors.blue,
),
),
const SizedBox(width: 8),
Text(
'${jadwal.jumlahBantuan} bantuan',
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
),
),
],
),
],
// Tombol lihat detail
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey.shade100,
),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 6),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Lihat Detail',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey.shade700,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_forward_ios,
size: 12,
color: Colors.grey.shade700,
),
],
),
),
],
),
],
],
),
),
),
),
);
}
IconData _getStatusIcon(String? status) {
switch (status) {
case 'SELESAI':
return Icons.check_circle;
case 'DIBATALKAN':
return Icons.cancel;
case 'DALAM_PROSES':
return Icons.timelapse;
default:
return Icons.event_available;
}
}
void _navigateToDetail(dynamic jadwal) {
Get.toNamed('/donatur/jadwal/${jadwal.id}', arguments: jadwal);
}
}

View File

@ -46,6 +46,19 @@ class _FormPenitipanBantuanState extends State<FormPenitipanBantuan> {
super.initState();
// Reset foto bantuan saat form dibuka
controller.resetFotoBantuan();
// Cek apakah ada skema bantuan yang dipilih dari halaman skema
if (controller.selectedSkemaBantuanId.isNotEmpty) {
// Aktifkan tab skema bantuan
setState(() {
selectedSkemaBantuanId = controller.selectedSkemaBantuanId.value;
});
// Reset ID skema setelah digunakan
Future.delayed(Duration.zero, () {
controller.selectedSkemaBantuanId.value = '';
});
}
}
@override
@ -214,6 +227,96 @@ class _FormPenitipanBantuanState extends State<FormPenitipanBantuan> {
return null;
},
),
const SizedBox(height: 8),
// Tampilkan informasi stok bantuan dari skema yang dipilih
Obx(() {
// Hanya tampilkan jika skema dipilih
if (selectedSkemaBantuanId == null ||
selectedSkemaBantuanId!.isEmpty) {
return const SizedBox.shrink();
}
// Cari skema bantuan yang dipilih
SkemaBantuanModel? selectedSkema;
try {
selectedSkema = controller.skemaBantuan.firstWhere(
(skema) => skema.id == selectedSkemaBantuanId,
);
} catch (_) {
return const SizedBox.shrink();
}
// Pastikan skema dan stok bantuan ada
if (selectedSkema.stokBantuanId == null) {
return const SizedBox.shrink();
}
// Cari stok bantuan yang sesuai
var stokBantuanFound = false;
var stokNama = 'Tidak diketahui';
var stokTotal = 0.0;
var stokSatuan = 'item';
for (var stok in controller.stokBantuan) {
if (stok.id == selectedSkema.stokBantuanId) {
stokBantuanFound = true;
stokNama = stok.nama ?? 'Tidak diketahui';
stokTotal = stok.totalStok ?? 0;
stokSatuan = stok.satuan ?? 'item';
break;
}
}
if (!stokBantuanFound) {
return const SizedBox.shrink();
}
// Tampilkan informasi stok bantuan
return Column(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.blue.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline,
color: Colors.blue.shade700, size: 18),
const SizedBox(width: 8),
Text(
'Informasi Stok Bantuan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blue.shade700,
),
),
],
),
const SizedBox(height: 8),
Text(
'Jenis Bantuan: $stokNama',
style: const TextStyle(fontSize: 14),
),
const SizedBox(height: 4),
Text(
'Stok Tersedia: $stokTotal $stokSatuan',
style: const TextStyle(fontSize: 14),
),
],
),
),
const SizedBox(height: 16)
],
);
}),
const SizedBox(height: 16),
] else ...[
// Form untuk bantuan manual

View File

@ -2,6 +2,9 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:penyaluran_app/app/modules/donatur/controllers/donatur_dashboard_controller.dart';
import 'package:penyaluran_app/app/widgets/section_header.dart';
import 'package:penyaluran_app/app/data/models/stok_bantuan_model.dart';
import 'package:penyaluran_app/app/utils/format_helper.dart';
import 'package:penyaluran_app/app/utils/date_helper.dart';
class DonaturSkemaView extends GetView<DonaturDashboardController> {
const DonaturSkemaView({super.key});
@ -98,7 +101,7 @@ class DonaturSkemaView extends GetView<DonaturDashboardController> {
color: Colors.grey.shade600,
),
),
const SizedBox(height: 16),
const SizedBox(height: 20),
...controller.skemaBantuan.map((skema) => _buildSkemaCard(skema)),
],
);
@ -106,43 +109,56 @@ class DonaturSkemaView extends GetView<DonaturDashboardController> {
Widget _buildSkemaCard(dynamic skema) {
return Container(
margin: const EdgeInsets.only(bottom: 16),
margin: const EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.blue.withOpacity(0.08),
blurRadius: 10,
offset: const Offset(0, 4),
color: Colors.blue.withOpacity(0.1),
blurRadius: 12,
offset: const Offset(0, 5),
spreadRadius: 1,
),
],
),
child: Card(
elevation: 0,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(16),
side: BorderSide(
color: Colors.blue.shade100,
width: 1,
),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header dengan warna gradient
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue.shade600, Colors.blue.shade800],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(12),
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(10),
),
child: Icon(
child: const Icon(
Icons.volunteer_activism,
color: Colors.blue.shade700,
size: 24,
color: Colors.white,
size: 22,
),
),
const SizedBox(width: 16),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -152,23 +168,28 @@ class DonaturSkemaView extends GetView<DonaturDashboardController> {
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 4),
if (skema.kuota != null)
_buildInfoChip(
icon: Icons.people_outline,
label: 'Kuota: ${skema.kuota} penerima',
color: Colors.blue.shade700,
),
if (skema.jumlahDiterimaPerOrang != null)
if (skema.batasWaktu != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: _buildInfoChip(
icon: Icons.inventory_2_outlined,
label:
'Jumlah per orang: ${skema.jumlahDiterimaPerOrang}',
color: Colors.green.shade700,
child: Row(
children: [
const Icon(
Icons.timer_outlined,
color: Colors.white70,
size: 14,
),
const SizedBox(width: 4),
Text(
_formatBatasWaktu(skema.batasWaktu),
style: const TextStyle(
fontSize: 12,
color: Colors.white70,
),
),
],
),
),
],
@ -176,76 +197,320 @@ class DonaturSkemaView extends GetView<DonaturDashboardController> {
),
],
),
const SizedBox(height: 16),
if (skema.deskripsi != null && skema.deskripsi!.isNotEmpty)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Deskripsi',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
// Konten utama
Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Status batas waktu jika hampir habis (kurang dari 7 hari)
if (skema.batasWaktu != null &&
_isDeadlineApproaching(skema.batasWaktu))
Container(
width: double.infinity,
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 12),
decoration: BoxDecoration(
color: Colors.orange.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.orange.shade200),
),
child: Row(
children: [
Icon(
Icons.warning_amber_rounded,
color: Colors.orange.shade700,
size: 18,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'Segera titipkan bantuan Anda! Batas waktu akan segera berakhir.',
style: TextStyle(
fontSize: 12,
color: Colors.orange.shade800,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
const SizedBox(height: 4),
Text(
skema.deskripsi!,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
),
),
const Divider(height: 24),
],
),
if (skema.kriteria != null && skema.kriteria!.isNotEmpty)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Kriteria Penerima',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
),
const SizedBox(height: 4),
Text(
skema.kriteria!,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
),
),
const SizedBox(height: 16),
],
),
ElevatedButton.icon(
onPressed: () {
// Navigasi ke formulir penitipan bantuan
controller.activeTabIndex.value = 3;
},
icon: const Icon(Icons.add_box_outlined, size: 18),
label: const Text('Titipkan Bantuan'),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.green.shade600,
minimumSize: const Size(double.infinity, 45),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
// Tambahkan informasi bantuan yang dibutuhkan
if (skema.stokBantuanId != null)
_buildBantuanDibutuhkan(skema.stokBantuanId!),
// Informasi kuota dan jumlah per orang
Row(
children: [
if (skema.kuota != null)
Expanded(
child: _buildInfoBox(
icon: Icons.people_outline,
title: 'Kuota',
value: '${skema.kuota} penerima',
color: Colors.blue.shade700,
),
),
const SizedBox(width: 12),
if (skema.jumlahDiterimaPerOrang != null)
Expanded(
child: _buildInfoBox(
icon: Icons.inventory_2_outlined,
title: 'Bantuan Per Orang',
value: _formatJumlahPerOrang(skema.stokBantuanId,
skema.jumlahDiterimaPerOrang!),
color: Colors.green.shade700,
),
),
],
),
const SizedBox(height: 16),
// Tombol titipkan bantuan
ElevatedButton.icon(
onPressed: () {
// Menyimpan ID skema bantuan yang dipilih
if (skema.id != null) {
controller.selectedSkemaBantuanId.value = skema.id!;
}
// Beralih ke tab penitipan bantuan
controller.activeTabIndex.value = 3;
},
icon: const Icon(Icons.add_box_outlined, size: 18),
label: const Text('Titipkan Bantuan'),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.green.shade600,
minimumSize: const Size(double.infinity, 48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 0,
),
),
],
),
),
],
),
),
);
}
Widget _buildBantuanDibutuhkan(String stokBantuanId) {
// Cari stok bantuan yang sesuai dengan ID di skema
final stokBantuan = controller.stokBantuan.firstWhere(
(stok) => stok.id == stokBantuanId,
orElse: () => StokBantuanModel(),
);
if (stokBantuan.id == null) return const SizedBox.shrink();
return Container(
width: double.infinity,
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.green.shade50,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.green.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.inventory_2,
color: Colors.green.shade700,
size: 18,
),
const SizedBox(width: 8),
Text(
'Bantuan yang Dibutuhkan',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.green.shade800,
),
),
],
),
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
stokBantuan.nama ?? 'Tidak tersedia',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
if (stokBantuan.kategoriBantuan != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
'Kategori: ${stokBantuan.kategoriBantuan!['nama'] ?? 'Umum'}',
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade700,
),
),
),
],
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: Colors.green.shade100,
borderRadius: BorderRadius.circular(16),
),
child: Row(
children: [
Icon(
Icons.inventory_rounded,
size: 16,
color: Colors.green.shade700,
),
const SizedBox(width: 4),
Text(
stokBantuan.isUang == true
? 'Stok: ${_formatRupiah(stokBantuan.totalStok)}'
: 'Stok: ${stokBantuan.totalStok?.toStringAsFixed(0) ?? '0'} ${stokBantuan.satuan ?? ''}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.bold,
color: Colors.green.shade800,
),
),
],
),
),
],
),
if (stokBantuan.deskripsi != null &&
stokBantuan.deskripsi!.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
stokBantuan.deskripsi!,
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade700,
),
),
),
],
),
);
}
Widget _buildInfoBox({
required IconData icon,
required String title,
required String value,
required Color color,
}) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: color.withOpacity(0.2)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
icon,
size: 16,
color: color,
),
const SizedBox(width: 6),
Text(
title,
style: TextStyle(
fontSize: 12,
color: color,
fontWeight: FontWeight.w500,
),
),
],
),
const SizedBox(height: 6),
Text(
value,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade800,
fontWeight: FontWeight.bold,
),
),
],
),
);
}
Widget _buildInfoSection({
required String title,
required String content,
required IconData icon,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
icon,
size: 16,
color: Colors.grey.shade700,
),
const SizedBox(width: 6),
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
),
],
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.all(12),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey.shade50,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey.shade200),
),
child: Text(
content,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
height: 1.4,
),
),
),
],
);
}
Widget _buildInfoChip({
required IconData icon,
required String label,
@ -270,4 +535,87 @@ class DonaturSkemaView extends GetView<DonaturDashboardController> {
],
);
}
// Fungsi untuk memformat tanggal batas waktu
String _formatBatasWaktu(DateTime? batasWaktu) {
if (batasWaktu == null) return '';
DateTime now = DateTime.now();
Duration difference = batasWaktu.difference(now);
if (difference.isNegative) {
return 'Batas waktu telah berakhir';
}
int days = difference.inDays;
if (days > 0) {
return 'Batas waktu: ${days} hari lagi';
} else {
int hours = difference.inHours;
if (hours > 0) {
return 'Batas waktu: ${hours} jam lagi';
} else {
int minutes = difference.inMinutes;
return 'Batas waktu: ${minutes} menit lagi';
}
}
}
// Cek apakah deadline mendekati (kurang dari 7 hari)
bool _isDeadlineApproaching(DateTime? batasWaktu) {
if (batasWaktu == null) return false;
DateTime now = DateTime.now();
Duration difference = batasWaktu.difference(now);
return difference.inDays < 7 && !difference.isNegative;
}
String _formatJumlahPerOrang(
String? stokBantuanId, dynamic jumlahDiterimaPerOrang) {
// Jika stokBantuanId null, kembalikan nilai apa adanya
if (stokBantuanId == null) return jumlahDiterimaPerOrang.toString();
// Cari stok bantuan berdasarkan ID
final stokBantuan = controller.stokBantuan.firstWhere(
(stok) => stok.id == stokBantuanId,
orElse: () => StokBantuanModel(),
);
// Jika nilai bantuan berupa uang, format sebagai Rupiah
if (stokBantuan.isUang == true) {
double nilai = 0;
if (jumlahDiterimaPerOrang is int) {
nilai = jumlahDiterimaPerOrang.toDouble();
} else if (jumlahDiterimaPerOrang is double) {
nilai = jumlahDiterimaPerOrang;
} else {
try {
nilai = double.parse(jumlahDiterimaPerOrang.toString());
} catch (e) {
return jumlahDiterimaPerOrang.toString();
}
}
// Format nilai sebagai Rupiah menggunakan DateHelper
return DateHelper.formatRupiah(nilai);
}
// Jika bukan uang, kembalikan nilai + satuan (jika ada)
return '${jumlahDiterimaPerOrang} ${stokBantuan.satuan ?? ''}';
}
String _formatRupiah(dynamic amount) {
if (amount is num) {
return DateHelper.formatRupiah(amount);
} else if (amount is String) {
try {
double nilai = double.parse(amount);
return DateHelper.formatRupiah(nilai);
} catch (e) {
return 'Rp ${amount.replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]}.')}';
}
} else {
return 'Rp 0';
}
}
}