kelola penyewa dan beberapa error fix
This commit is contained in:
@ -185,7 +185,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
errorMessage.value,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -211,7 +211,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Info',
|
||||
'Tidak dapat menampilkan data - data tidak tersedia',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.amber,
|
||||
colorText: Colors.black,
|
||||
duration: const Duration(seconds: 3),
|
||||
@ -231,6 +231,9 @@ class OrderSewaAsetController extends GetxController {
|
||||
debugPrint('💾 Saved asetId to GetStorage: ${asetId.value}');
|
||||
}
|
||||
|
||||
// Bersihkan data controller
|
||||
clearData();
|
||||
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@ -445,6 +448,9 @@ class OrderSewaAsetController extends GetxController {
|
||||
void onBackPressed() {
|
||||
debugPrint('🔙 Back button pressed in OrderSewaAsetView');
|
||||
|
||||
// Bersihkan data controller sebelum kembali
|
||||
clearData();
|
||||
|
||||
try {
|
||||
// Try to use the navigation service
|
||||
navigationService.backFromOrderSewaAset();
|
||||
@ -2287,7 +2293,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
message,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -2299,7 +2305,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
message,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -2767,7 +2773,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal membuat pesanan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -2777,7 +2783,7 @@ class OrderSewaAsetController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Terjadi kesalahan: $e',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -3537,4 +3543,43 @@ class OrderSewaAsetController extends GetxController {
|
||||
isLoadingBookings(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear controller data
|
||||
void clearData() {
|
||||
aset.value = null;
|
||||
isLoading.value = true;
|
||||
hasError.value = false;
|
||||
errorMessage.value = '';
|
||||
asetId.value = '';
|
||||
isAset.value = true;
|
||||
isPaket.value = false;
|
||||
assetPhotos.clear();
|
||||
currentPhotoIndex.value = 0;
|
||||
isPhotosLoading.value = false;
|
||||
selectedSatuanWaktu.value = null;
|
||||
duration.value = 1;
|
||||
totalPrice.value = 0;
|
||||
jumlahUnit.value = 1;
|
||||
maxUnit.value = 1;
|
||||
selectedDate.value = '';
|
||||
startHour.value = -1;
|
||||
endHour.value = -1;
|
||||
formattedTimeRange.value = '';
|
||||
startDate.value = null;
|
||||
endDate.value = null;
|
||||
formattedDateRange.value = '';
|
||||
bookedDates.clear();
|
||||
isLoadingBookedDates.value = false;
|
||||
maxDayLimit.value = 0;
|
||||
availableHours.clear();
|
||||
bookedHours.clear();
|
||||
selectedHours.clear();
|
||||
bookedHoursList.clear();
|
||||
isLoadingBookings.value = false;
|
||||
hourlyInventory.clear();
|
||||
unavailableDatesForHourly.clear();
|
||||
paketItems.clear();
|
||||
isPaketItemsLoaded.value = false;
|
||||
paketId.value = '';
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memuat data paket',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -152,7 +152,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Terjadi kesalahan saat memuat data paket',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -166,10 +166,10 @@ class OrderSewaPaketController extends GetxController {
|
||||
try {
|
||||
debugPrint('🔄 Processing paket data for ID: $id');
|
||||
debugPrint('📦 Raw paket data type: ${rawPaket.runtimeType}');
|
||||
|
||||
|
||||
// Initialize loadedPaket with a default value
|
||||
late final PaketModel loadedPaket;
|
||||
|
||||
|
||||
try {
|
||||
// Handle Map directly - pakets from getPakets() are always maps
|
||||
loadedPaket = PaketModel.fromMap(rawPaket);
|
||||
@ -183,10 +183,16 @@ class OrderSewaPaketController extends GetxController {
|
||||
deskripsi: getPaketDeskripsi(rawPaket),
|
||||
harga: getPaketHarga(rawPaket),
|
||||
kuantitas: getPaketKuantitas(rawPaket),
|
||||
foto: const <String>[], // Initialize with empty list, will be populated later
|
||||
foto:
|
||||
const <
|
||||
String
|
||||
>[], // Initialize with empty list, will be populated later
|
||||
satuanWaktuSewa: getPaketSatuanWaktuSewa(rawPaket),
|
||||
foto_paket: getPaketMainPhoto(rawPaket),
|
||||
images: const <String>[], // Initialize with empty list, will be populated later
|
||||
images:
|
||||
const <
|
||||
String
|
||||
>[], // Initialize with empty list, will be populated later
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
@ -352,7 +358,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
if (items.isNotEmpty) {
|
||||
paketItems.value = items;
|
||||
debugPrint('✅ Loaded ${paketItems.length} package items');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ Error loading paket items: $e');
|
||||
paketItems.value = [];
|
||||
@ -1030,7 +1036,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Waktu Tidak Tersedia',
|
||||
'Jam ini tidak tersedia karena ada aset dalam paket yang sudah dipesan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.orange,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1114,7 +1120,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Data paket tidak lengkap',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1131,7 +1137,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Silakan pilih waktu sewa',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1163,7 +1169,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
durasi: orderData['durasi'] ?? 1, // Default to 1 if not provided
|
||||
totalHarga: orderData['total_harga'].toInt(),
|
||||
);
|
||||
|
||||
|
||||
// Create a mock result for navigation
|
||||
final resultData = {
|
||||
'id': 'order_${DateTime.now().millisecondsSinceEpoch}',
|
||||
@ -1174,21 +1180,23 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Pesanan berhasil dibuat',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
||||
// Navigate to payment page
|
||||
if (result && resultData != null && resultData['id'] != null) {
|
||||
navigationService.navigateToPembayaranSewa(resultData['id'].toString());
|
||||
navigationService.navigateToPembayaranSewa(
|
||||
resultData['id'].toString(),
|
||||
);
|
||||
} else if (result) {
|
||||
// If result is true but we don't have an ID, navigate back to sewa aset
|
||||
navigationService.navigateToSewaAset();
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal mendapatkan ID pesanan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1196,7 +1204,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal membuat pesanan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1205,7 +1213,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal membuat pesanan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1215,7 +1223,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Terjadi kesalahan: $e',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1392,7 +1400,7 @@ class OrderSewaPaketController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Peringatan',
|
||||
'Pilih tanggal terlebih dahulu',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.orange,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
@ -378,7 +378,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Pesanan Dibatalkan',
|
||||
'Batas waktu pembayaran telah berakhir',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
duration: Duration(seconds: 5),
|
||||
@ -417,7 +417,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal mengambil foto: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -443,7 +443,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memilih foto dari galeri: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -459,7 +459,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Mohon unggah bukti pembayaran terlebih dahulu',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -541,7 +541,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Bukti pembayaran berhasil diunggah',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -550,7 +550,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal mengunggah bukti pembayaran: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -654,7 +654,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Pembayaran tunai berhasil disubmit',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1090,7 +1090,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Berhasil',
|
||||
'Data berhasil diperbarui',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 2),
|
||||
@ -1104,7 +1104,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memperbarui data',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
@ -305,6 +305,9 @@ class PembayaranSewaController extends GetxController
|
||||
: 0,
|
||||
'status': rentalData['status'] ?? 'MENUNGGU PEMBAYARAN',
|
||||
'created_at': DateTime.now().toString(),
|
||||
'updated_at':
|
||||
DateTime.now()
|
||||
.toString(), // Explicitly set updated_at for countdown
|
||||
'denda': 0, // Default value
|
||||
'keterangan': '', // Default value
|
||||
'image_url': rentalData['imageUrl'],
|
||||
@ -359,13 +362,19 @@ class PembayaranSewaController extends GetxController
|
||||
'price_per_unit': 10000,
|
||||
'total_price': 50000,
|
||||
'status': 'MENUNGGU PEMBAYARAN',
|
||||
'created_at':
|
||||
DateTime.now().toString(), // Use this for countdown calculation
|
||||
'created_at': DateTime.now().toString(),
|
||||
'updated_at':
|
||||
DateTime.now()
|
||||
.toString(), // Explicitly set updated_at for countdown
|
||||
'denda': 20000, // Dummy data for denda
|
||||
'keterangan':
|
||||
'Terjadi kerusakan pada bagian kaki', // Dummy keterangan for denda
|
||||
};
|
||||
|
||||
debugPrint(
|
||||
'DEBUG: Set updated_at in orderDetails: ${orderDetails.value['updated_at']}',
|
||||
);
|
||||
|
||||
// Update the current step based on the status
|
||||
updateCurrentStepBasedOnStatus();
|
||||
|
||||
@ -433,14 +442,27 @@ class PembayaranSewaController extends GetxController
|
||||
if (data['status'] != null &&
|
||||
data['status'].toString().isNotEmpty) {
|
||||
val?['status'] = data['status'];
|
||||
debugPrint(
|
||||
'📊 Order status from sewa_aset: \\${data['status']}',
|
||||
);
|
||||
debugPrint('📊 Order status from sewa_aset: ${data['status']}');
|
||||
}
|
||||
// Tambahkan mapping updated_at
|
||||
|
||||
// Ensure updated_at is always set
|
||||
if (data['updated_at'] != null) {
|
||||
val?['updated_at'] = data['updated_at'];
|
||||
debugPrint(
|
||||
'📅 Using updated_at from database: ${data['updated_at']}',
|
||||
);
|
||||
} else if (data['created_at'] != null) {
|
||||
val?['updated_at'] = data['created_at'];
|
||||
debugPrint(
|
||||
'📅 Using created_at as fallback for updated_at: ${data['created_at']}',
|
||||
);
|
||||
} else {
|
||||
val?['updated_at'] = DateTime.now().toIso8601String();
|
||||
debugPrint(
|
||||
'📅 Using current timestamp as fallback for updated_at',
|
||||
);
|
||||
}
|
||||
|
||||
// Format rental period
|
||||
if (data['waktu_mulai'] != null &&
|
||||
data['waktu_selesai'] != null) {
|
||||
@ -448,12 +470,12 @@ class PembayaranSewaController extends GetxController
|
||||
final startTime = DateTime.parse(data['waktu_mulai']);
|
||||
final endTime = DateTime.parse(data['waktu_selesai']);
|
||||
val?['rental_period'] =
|
||||
'\\${startTime.day}/\\${startTime.month}/\\${startTime.year}, \\${startTime.hour}:\\${startTime.minute.toString().padLeft(2, '0')} - \\${endTime.hour}:\\${endTime.minute.toString().padLeft(2, '0')}';
|
||||
'${startTime.day}/${startTime.month}/${startTime.year}, ${startTime.hour}:${startTime.minute.toString().padLeft(2, '0')} - ${endTime.hour}:${endTime.minute.toString().padLeft(2, '0')}';
|
||||
debugPrint(
|
||||
'✅ Successfully formatted rental period: \\${val?['rental_period']}',
|
||||
'✅ Successfully formatted rental period: ${val?['rental_period']}',
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('❌ Error parsing date: \\${e}');
|
||||
debugPrint('❌ Error parsing date: ${e}');
|
||||
}
|
||||
} else {
|
||||
debugPrint(
|
||||
@ -577,7 +599,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Pesanan Dibatalkan',
|
||||
'Batas waktu pembayaran telah berakhir',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
duration: Duration(seconds: 5),
|
||||
@ -624,7 +646,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal mengambil foto: \\${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -653,7 +675,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memilih foto dari galeri: \\${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -679,7 +701,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Mohon unggah bukti pembayaran terlebih dahulu',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -691,7 +713,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Info',
|
||||
'Tidak ada perubahan yang perlu disimpan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.blue,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -843,7 +865,7 @@ class PembayaranSewaController extends GetxController
|
||||
val?['status'] == 'PEMBAYARAN DENDA') {
|
||||
val?['status'] = 'PERIKSA PEMBAYARAN DENDA';
|
||||
} else {
|
||||
val?['status'] = 'MEMERIKSA PEMBAYARAN';
|
||||
val?['status'] = 'PERIKSA PEMBAYARAN';
|
||||
}
|
||||
});
|
||||
|
||||
@ -894,7 +916,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Bukti pembayaran berhasil diunggah',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -903,7 +925,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal mengunggah bukti pembayaran: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -930,19 +952,19 @@ class PembayaranSewaController extends GetxController
|
||||
newStatus = 'MENUNGGU PEMBAYARAN';
|
||||
break;
|
||||
case 1:
|
||||
newStatus = 'MEMERIKSA PEMBAYARAN';
|
||||
newStatus = 'PERIKSA PEMBAYARAN';
|
||||
break;
|
||||
case 2:
|
||||
newStatus = 'DITERIMA';
|
||||
break;
|
||||
case 3:
|
||||
newStatus = 'PENGEMBALIAN';
|
||||
newStatus = 'DIKEMBALIKAN';
|
||||
break;
|
||||
case 4:
|
||||
newStatus = 'PEMBAYARAN DENDA';
|
||||
break;
|
||||
case 5:
|
||||
newStatus = 'MEMERIKSA PEMBAYARAN DENDA';
|
||||
newStatus = 'PERIKSA PEMBAYARAN DENDA';
|
||||
break;
|
||||
case 6:
|
||||
newStatus = 'SELESAI';
|
||||
@ -965,7 +987,7 @@ class PembayaranSewaController extends GetxController
|
||||
case 'MENUNGGU PEMBAYARAN':
|
||||
currentStep.value = 0;
|
||||
break;
|
||||
case 'MEMERIKSA PEMBAYARAN':
|
||||
case 'PERIKSA PEMBAYARAN':
|
||||
currentStep.value = 1;
|
||||
break;
|
||||
case 'DITERIMA':
|
||||
@ -974,7 +996,7 @@ class PembayaranSewaController extends GetxController
|
||||
case 'AKTIF':
|
||||
currentStep.value = 3;
|
||||
break;
|
||||
case 'PENGEMBALIAN':
|
||||
case 'DIKEMBALIKAN':
|
||||
currentStep.value = 4;
|
||||
break;
|
||||
case 'PEMBAYARAN DENDA':
|
||||
@ -1003,7 +1025,7 @@ class PembayaranSewaController extends GetxController
|
||||
void submitCashPayment() {
|
||||
// Update order status
|
||||
orderDetails.update((val) {
|
||||
val?['status'] = 'MEMERIKSA PEMBAYARAN';
|
||||
val?['status'] = 'PERIKSA PEMBAYARAN';
|
||||
});
|
||||
|
||||
// Cancel countdown timer as payment has been submitted
|
||||
@ -1013,7 +1035,7 @@ class PembayaranSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Pembayaran tunai berhasil disubmit',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1266,7 +1288,20 @@ class PembayaranSewaController extends GetxController
|
||||
updateCurrentStepBasedOnStatus();
|
||||
|
||||
// Restart countdown timer if needed
|
||||
if (orderDetails.value['status'] == 'MENUNGGU PEMBAYARAN') {
|
||||
if ((orderDetails.value['status'] ?? '').toString().toUpperCase() ==
|
||||
'MENUNGGU PEMBAYARAN') {
|
||||
debugPrint('Status is MENUNGGU PEMBAYARAN, restarting countdown timer');
|
||||
|
||||
// Ensure updated_at is set to current time if refreshing with MENUNGGU PEMBAYARAN status
|
||||
if (orderDetails.value['updated_at'] == null) {
|
||||
orderDetails.update((val) {
|
||||
val?['updated_at'] = DateTime.now().toIso8601String();
|
||||
});
|
||||
debugPrint(
|
||||
'Set updated_at to current time: ${orderDetails.value['updated_at']}',
|
||||
);
|
||||
}
|
||||
|
||||
_countdownTimer?.cancel();
|
||||
startCountdownTimer();
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Terjadi kesalahan saat memuat data aset',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -279,7 +279,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
message,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -321,7 +321,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Pesanan berhasil dibuat',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -383,7 +383,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Terjadi kesalahan saat memuat data paket',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -429,7 +429,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memuat data paket. Silakan coba lagi nanti.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -470,7 +470,7 @@ class SewaAsetController extends GetxController
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Pesanan paket berhasil dibuat',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
@ -46,30 +46,51 @@ class WargaDashboardController extends GetxController {
|
||||
final dendaAktifCount = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
|
||||
// Set navigation index to Home (0)
|
||||
navigationService.setNavIndex(0);
|
||||
|
||||
// Load user data
|
||||
fetchProfileFromWargaDesa();
|
||||
_loadUserData();
|
||||
// Check if navigation is coming from login
|
||||
final args = Get.arguments;
|
||||
final bool isFromLogin = args != null && args['from_login'] == true;
|
||||
|
||||
// Load sample data
|
||||
_loadSampleData();
|
||||
if (isFromLogin) {
|
||||
print('onInit: Navigation from login detected, prioritizing data fetch');
|
||||
}
|
||||
|
||||
// Load dummy data for bills and penalties
|
||||
loadDummyData();
|
||||
// Verifikasi bahwa pengguna sudah login sebelum melakukan fetch data
|
||||
if (_authProvider.currentUser != null) {
|
||||
// Prioritize loading user profile data first
|
||||
await fetchProfileFromWargaDesa();
|
||||
|
||||
// Load unpaid rentals
|
||||
loadUnpaidRentals();
|
||||
// If the profile data was not loaded successfully, try again after a short delay
|
||||
if (userName.value == 'Pengguna Warga' || userNik.value.isEmpty) {
|
||||
print('onInit: Profile data not loaded, retrying after delay');
|
||||
await Future.delayed(const Duration(milliseconds: 800));
|
||||
await fetchProfileFromWargaDesa();
|
||||
}
|
||||
|
||||
// Debug count sewa_aset by status
|
||||
_debugCountSewaAset();
|
||||
// Load other user data
|
||||
await _loadUserData();
|
||||
|
||||
// Load sewa aktif
|
||||
loadActiveRentals();
|
||||
// Load other data in parallel to speed up the dashboard initialization
|
||||
Future.wait([
|
||||
_loadSampleData(),
|
||||
loadDummyData(),
|
||||
loadUnpaidRentals(),
|
||||
_debugCountSewaAset(),
|
||||
loadActiveRentals(),
|
||||
]).then((_) => print('onInit: All data loaded successfully'));
|
||||
|
||||
// If coming from login, make sure UI is updated
|
||||
if (isFromLogin) {
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
print('onInit: User not logged in, skipping data fetch');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadUserData() async {
|
||||
@ -116,7 +137,7 @@ class WargaDashboardController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void _loadSampleData() {
|
||||
Future<void> _loadSampleData() async {
|
||||
// Clear any existing data
|
||||
activeRentals.clear();
|
||||
|
||||
@ -147,10 +168,37 @@ class WargaDashboardController extends GetxController {
|
||||
navigationService.toSewaAset();
|
||||
}
|
||||
|
||||
void refreshData() {
|
||||
fetchProfileFromWargaDesa();
|
||||
_loadSampleData();
|
||||
loadDummyData();
|
||||
Future<void> refreshData() async {
|
||||
print('refreshData: Refreshing dashboard data');
|
||||
try {
|
||||
// First fetch profile data
|
||||
await fetchProfileFromWargaDesa();
|
||||
await _loadUserData();
|
||||
|
||||
// Then load all other data in parallel
|
||||
await Future.wait([
|
||||
_loadSampleData(),
|
||||
loadDummyData(),
|
||||
loadUnpaidRentals(),
|
||||
loadActiveRentals(),
|
||||
_debugCountSewaAset(),
|
||||
]);
|
||||
|
||||
// Update UI
|
||||
update();
|
||||
print('refreshData: Dashboard data refreshed successfully');
|
||||
} catch (e) {
|
||||
print('refreshData: Error refreshing data: $e');
|
||||
// Show error message to user
|
||||
Get.snackbar(
|
||||
'Perhatian',
|
||||
'Terjadi kesalahan saat memuat data',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red.shade100,
|
||||
colorText: Colors.red.shade900,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void onNavItemTapped(int index) {
|
||||
@ -176,12 +224,14 @@ class WargaDashboardController extends GetxController {
|
||||
Get.toNamed(Routes.WARGA_SEWA, arguments: {'tab': 3});
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
Future<void> logout() async {
|
||||
print('logout: Logging out user');
|
||||
await _authProvider.signOut();
|
||||
navigationService.toLogin();
|
||||
print('logout: User logged out and redirected to login screen');
|
||||
}
|
||||
|
||||
void loadDummyData() {
|
||||
Future<void> loadDummyData() async {
|
||||
// Dummy active bills
|
||||
activeBills.clear();
|
||||
activeBills.add({
|
||||
@ -331,24 +381,77 @@ class WargaDashboardController extends GetxController {
|
||||
Future<void> fetchProfileFromWargaDesa() async {
|
||||
try {
|
||||
final user = _authProvider.currentUser;
|
||||
if (user == null) return;
|
||||
if (user == null) {
|
||||
print(
|
||||
'fetchProfileFromWargaDesa: No current user found, skipping fetch',
|
||||
);
|
||||
return; // Exit early if no user is logged in
|
||||
}
|
||||
|
||||
final userId = user.id;
|
||||
print('fetchProfileFromWargaDesa: Fetching data for user: $userId');
|
||||
|
||||
final data =
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.select('nik, alamat, email, nama_lengkap, no_hp, avatar')
|
||||
.eq('user_id', userId)
|
||||
.maybeSingle();
|
||||
|
||||
if (data != null) {
|
||||
print('fetchProfileFromWargaDesa: Data retrieved successfully');
|
||||
userNik.value = data['nik']?.toString() ?? '';
|
||||
userAddress.value = data['alamat']?.toString() ?? '';
|
||||
userEmail.value = data['email']?.toString() ?? '';
|
||||
userName.value = data['nama_lengkap']?.toString() ?? '';
|
||||
userPhone.value = data['no_hp']?.toString() ?? '';
|
||||
userAvatar.value = data['avatar']?.toString() ?? '';
|
||||
|
||||
// Trigger UI refresh
|
||||
update();
|
||||
print('fetchProfileFromWargaDesa: Profile data updated');
|
||||
} else {
|
||||
print('fetchProfileFromWargaDesa: No data found for user: $userId');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching profile from warga_desa: $e');
|
||||
// If it fails, try again after a delay
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
try {
|
||||
await _retryFetchProfile();
|
||||
} catch (retryError) {
|
||||
print('Retry error fetching profile: $retryError');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to retry fetching profile
|
||||
Future<void> _retryFetchProfile() async {
|
||||
final user = _authProvider.currentUser;
|
||||
if (user == null) {
|
||||
print('_retryFetchProfile: No current user found, skipping retry');
|
||||
return; // Exit early if no user is logged in
|
||||
}
|
||||
|
||||
print('_retryFetchProfile: Retrying fetch for user: ${user.id}');
|
||||
|
||||
final data =
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.select('nik, alamat, email, nama_lengkap, no_hp, avatar')
|
||||
.eq('user_id', user.id)
|
||||
.maybeSingle();
|
||||
|
||||
if (data != null) {
|
||||
print('_retryFetchProfile: Data retrieved successfully on retry');
|
||||
userNik.value = data['nik']?.toString() ?? '';
|
||||
userAddress.value = data['alamat']?.toString() ?? '';
|
||||
userEmail.value = data['email']?.toString() ?? '';
|
||||
userName.value = data['nama_lengkap']?.toString() ?? '';
|
||||
userPhone.value = data['no_hp']?.toString() ?? '';
|
||||
userAvatar.value = data['avatar']?.toString() ?? '';
|
||||
update();
|
||||
print('_retryFetchProfile: Profile data updated');
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,7 +636,7 @@ class WargaDashboardController extends GetxController {
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Tidak dapat mengakses ${source == ImageSource.camera ? 'kamera' : 'galeri'}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red.shade700,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
|
@ -254,10 +254,28 @@ class WargaSewaController extends GetxController
|
||||
|
||||
debugPrint('Fetched ${sewaAsetList.length} sewa_aset records');
|
||||
|
||||
// Debug the structure of the first record if available
|
||||
if (sewaAsetList.isNotEmpty) {
|
||||
debugPrint('Sample sewa_aset record: ${sewaAsetList.first}');
|
||||
debugPrint('updated_at field: ${sewaAsetList.first['updated_at']}');
|
||||
}
|
||||
|
||||
// Process each sewa_aset record
|
||||
for (var sewaAset in sewaAsetList) {
|
||||
final processedData = await _processRentalData(sewaAset);
|
||||
processedData['status'] = sewaAset['status'] ?? 'MENUNGGU PEMBAYARAN';
|
||||
|
||||
// Ensure updated_at is set correctly
|
||||
if (sewaAset['updated_at'] == null &&
|
||||
processedData['status'] == 'MENUNGGU PEMBAYARAN') {
|
||||
// If updated_at is null but status is MENUNGGU PEMBAYARAN, use created_at as fallback
|
||||
processedData['updated_at'] =
|
||||
sewaAset['created_at'] ?? DateTime.now().toIso8601String();
|
||||
debugPrint(
|
||||
'Using created_at as fallback for updated_at: ${processedData['updated_at']}',
|
||||
);
|
||||
}
|
||||
|
||||
rentals.add(processedData);
|
||||
}
|
||||
|
||||
@ -321,7 +339,7 @@ class WargaSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Berhasil',
|
||||
'Pesanan berhasil dibatalkan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -337,7 +355,7 @@ class WargaSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Gagal membatalkan pesanan: $e',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -377,7 +395,7 @@ class WargaSewaController extends GetxController
|
||||
Get.snackbar(
|
||||
'Info',
|
||||
'Navigasi ke halaman pembayaran',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -285,9 +285,10 @@ class OrderSewaAsetView extends GetView<OrderSewaAsetController> {
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
// Handle back button press here
|
||||
handleBackButtonPress();
|
||||
return false; // We handle the navigation ourselves
|
||||
// Bersihkan controller saat pengguna keluar dari halaman dengan tombol back perangkat
|
||||
controller.clearData();
|
||||
debugPrint('🧹 Controller data cleared by WillPopScope');
|
||||
return true;
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
@ -474,108 +475,60 @@ class OrderSewaAsetView extends GetView<OrderSewaAsetController> {
|
||||
},
|
||||
// Add onTap handler for the image
|
||||
onTap: () {
|
||||
debugPrint("📸 Image tapped - opening fullscreen viewer");
|
||||
final imageUrl = controller.getCurrentPhotoUrl();
|
||||
if (imageUrl != null && imageUrl.isNotEmpty) {
|
||||
debugPrint("📸 Current image URL: $imageUrl");
|
||||
debugPrint("📸 Total photos: ${controller.assetPhotos.length}");
|
||||
debugPrint(
|
||||
"📸 Image tapped - attempting to open fullscreen viewer",
|
||||
);
|
||||
try {
|
||||
final imageUrl = controller.getCurrentPhotoUrl();
|
||||
if (imageUrl != null && imageUrl.isNotEmpty) {
|
||||
debugPrint("📸 Current image URL: $imageUrl");
|
||||
debugPrint(
|
||||
"📸 Total photos: ${controller.assetPhotos.length}",
|
||||
);
|
||||
|
||||
// Extract all image URLs from the assetPhotos collection
|
||||
final List<String> photoUrls = [];
|
||||
for (var photo in controller.assetPhotos) {
|
||||
final url = photo.fotoAset;
|
||||
if (url.isNotEmpty) {
|
||||
photoUrls.add(url);
|
||||
debugPrint("📸 Added photo URL: $url");
|
||||
// Extract all image URLs from the assetPhotos collection
|
||||
final List<String> photoUrls = [];
|
||||
for (var photo in controller.assetPhotos) {
|
||||
final url = photo.fotoAset;
|
||||
if (url.isNotEmpty) {
|
||||
photoUrls.add(url);
|
||||
debugPrint("📸 Added photo URL: $url");
|
||||
}
|
||||
}
|
||||
|
||||
if (photoUrls.isEmpty) {
|
||||
debugPrint("📸 No valid photo URLs found");
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
"📸 About to navigate to fullscreen viewer with ${photoUrls.length} photos",
|
||||
);
|
||||
|
||||
// Navigate to full screen image viewer using GetX
|
||||
Get.to(
|
||||
() => FullScreenImageViewer(
|
||||
imageUrls: photoUrls,
|
||||
initialIndex: controller.currentPhotoIndex.value,
|
||||
),
|
||||
fullscreenDialog: true,
|
||||
transition: Transition.fade,
|
||||
);
|
||||
|
||||
debugPrint("📸 Navigation initiated");
|
||||
} else {
|
||||
debugPrint("📸 No valid current image URL");
|
||||
}
|
||||
|
||||
if (photoUrls.isEmpty) {
|
||||
debugPrint("📸 No valid photo URLs found");
|
||||
return;
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder:
|
||||
(context) => Dialog(
|
||||
insetPadding: EdgeInsets.zero,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: Colors.black,
|
||||
child: Stack(
|
||||
children: [
|
||||
// Image
|
||||
Center(
|
||||
child: InteractiveViewer(
|
||||
panEnabled: true,
|
||||
boundaryMargin: EdgeInsets.all(80),
|
||||
minScale: 0.5,
|
||||
maxScale: 4,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl:
|
||||
photoUrls[controller
|
||||
.currentPhotoIndex
|
||||
.value],
|
||||
fit: BoxFit.contain,
|
||||
placeholder:
|
||||
(context, url) => Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
errorWidget:
|
||||
(context, url, error) => Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.broken_image_rounded,
|
||||
size: 64,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Gagal memuat foto',
|
||||
style: TextStyle(
|
||||
color: Colors.grey[600],
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Close button
|
||||
Positioned(
|
||||
top: 40,
|
||||
right: 20,
|
||||
child: IconButton(
|
||||
icon: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
} catch (e) {
|
||||
debugPrint("📸 ERROR in image tap handler: $e");
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Failed to open image viewer',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red.shade100,
|
||||
colorText: Colors.red.shade900,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
} else {
|
||||
debugPrint("📸 No valid current image URL");
|
||||
}
|
||||
},
|
||||
child: ClipRRect(
|
||||
@ -667,17 +620,19 @@ class OrderSewaAsetView extends GetView<OrderSewaAsetController> {
|
||||
|
||||
// Gradient overlay
|
||||
Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.black.withOpacity(0.1),
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.3),
|
||||
],
|
||||
stops: [0.0, 0.6, 1.0],
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.black.withOpacity(0.1),
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.3),
|
||||
],
|
||||
stops: [0.0, 0.6, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -687,13 +642,15 @@ class OrderSewaAsetView extends GetView<OrderSewaAsetController> {
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
right: 16,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: IgnorePointer(
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(Icons.zoom_in, color: Colors.white, size: 24),
|
||||
),
|
||||
child: Icon(Icons.zoom_in, color: Colors.white, size: 24),
|
||||
),
|
||||
),
|
||||
|
||||
@ -1058,88 +1015,176 @@ class OrderSewaAsetView extends GetView<OrderSewaAsetController> {
|
||||
asetId,
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
return Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
8,
|
||||
),
|
||||
color:
|
||||
AppColors
|
||||
.surfaceLight,
|
||||
),
|
||||
child:
|
||||
snapshot.connectionState ==
|
||||
ConnectionState
|
||||
.waiting
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth:
|
||||
2,
|
||||
color:
|
||||
AppColors
|
||||
.primary,
|
||||
),
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
debugPrint(
|
||||
"📸 Package item image tapped - attempting to open fullscreen viewer for asset ID: $asetId",
|
||||
);
|
||||
try {
|
||||
// Get all photos for this asset
|
||||
final photos =
|
||||
await controller
|
||||
.asetProvider
|
||||
.getAsetPhotos(
|
||||
asetId,
|
||||
);
|
||||
if (photos.isEmpty) {
|
||||
debugPrint(
|
||||
"📸 No photos found for asset ID: $asetId",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract valid photo URLs
|
||||
final List<String>
|
||||
photoUrls = [];
|
||||
for (var photo
|
||||
in photos) {
|
||||
final url =
|
||||
photo.fotoAset;
|
||||
if (url.isNotEmpty) {
|
||||
photoUrls.add(url);
|
||||
debugPrint(
|
||||
"📸 Added photo URL: $url",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (photoUrls.isEmpty) {
|
||||
debugPrint(
|
||||
"📸 No valid photo URLs found",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
"📸 About to navigate to fullscreen viewer with ${photoUrls.length} photos",
|
||||
);
|
||||
|
||||
// Navigate to full screen image viewer using GetX
|
||||
Get.to(
|
||||
() =>
|
||||
FullScreenImageViewer(
|
||||
imageUrls:
|
||||
photoUrls,
|
||||
initialIndex: 0,
|
||||
),
|
||||
)
|
||||
: snapshot.data !=
|
||||
null
|
||||
? ClipRRect(
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
8,
|
||||
fullscreenDialog:
|
||||
true,
|
||||
transition:
|
||||
Transition.fade,
|
||||
);
|
||||
|
||||
debugPrint(
|
||||
"📸 Navigation initiated",
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint(
|
||||
"📸 ERROR in package item image tap handler: $e",
|
||||
);
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Failed to open image viewer',
|
||||
snackPosition:
|
||||
SnackPosition
|
||||
.BOTTOM,
|
||||
backgroundColor:
|
||||
Colors
|
||||
.red
|
||||
.shade100,
|
||||
colorText:
|
||||
Colors
|
||||
.red
|
||||
.shade900,
|
||||
duration:
|
||||
const Duration(
|
||||
seconds: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
8,
|
||||
),
|
||||
color:
|
||||
AppColors
|
||||
.surfaceLight,
|
||||
),
|
||||
child:
|
||||
snapshot.connectionState ==
|
||||
ConnectionState
|
||||
.waiting
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth:
|
||||
2,
|
||||
color:
|
||||
AppColors
|
||||
.primary,
|
||||
),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl:
|
||||
snapshot
|
||||
.data!,
|
||||
fit:
|
||||
BoxFit
|
||||
.cover,
|
||||
placeholder:
|
||||
(
|
||||
context,
|
||||
url,
|
||||
) => Center(
|
||||
child: SizedBox(
|
||||
width:
|
||||
20,
|
||||
height:
|
||||
20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth:
|
||||
2,
|
||||
color:
|
||||
AppColors.primary,
|
||||
),
|
||||
)
|
||||
: snapshot.data !=
|
||||
null
|
||||
? ClipRRect(
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
8,
|
||||
),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl:
|
||||
snapshot
|
||||
.data!,
|
||||
fit:
|
||||
BoxFit
|
||||
.cover,
|
||||
placeholder:
|
||||
(
|
||||
context,
|
||||
url,
|
||||
) => Center(
|
||||
child: SizedBox(
|
||||
width:
|
||||
20,
|
||||
height:
|
||||
20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth:
|
||||
2,
|
||||
color:
|
||||
AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
errorWidget:
|
||||
(
|
||||
context,
|
||||
url,
|
||||
error,
|
||||
) => Icon(
|
||||
Icons
|
||||
.image_not_supported_outlined,
|
||||
color:
|
||||
AppColors
|
||||
.textLight,
|
||||
),
|
||||
errorWidget:
|
||||
(
|
||||
context,
|
||||
url,
|
||||
error,
|
||||
) => Icon(
|
||||
Icons
|
||||
.image_not_supported_outlined,
|
||||
color:
|
||||
AppColors.textLight,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
Icons
|
||||
.image_not_supported_outlined,
|
||||
color:
|
||||
AppColors
|
||||
.textLight,
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
Icons
|
||||
.image_not_supported_outlined,
|
||||
color:
|
||||
AppColors
|
||||
.textLight,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -2458,98 +2503,173 @@ class _FullScreenImageViewerState extends State<FullScreenImageViewer> {
|
||||
for (int i = 0; i < widget.imageUrls.length && i < 3; i++) {
|
||||
debugPrint("📸 Image URL $i: ${widget.imageUrls[i]}");
|
||||
}
|
||||
|
||||
// Hide status bar for immersive view
|
||||
SystemChrome.setEnabledSystemUIMode(
|
||||
SystemUiMode.manual,
|
||||
overlays: [], // Hide all system UI
|
||||
).catchError((error) {
|
||||
debugPrint("📸 Error setting system UI mode: $error");
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Restore status bar when exiting
|
||||
SystemChrome.setEnabledSystemUIMode(
|
||||
SystemUiMode.manual,
|
||||
overlays: SystemUiOverlay.values, // Restore all system UI
|
||||
).catchError((error) {
|
||||
debugPrint("📸 Error restoring system UI mode: $error");
|
||||
});
|
||||
|
||||
pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
// Photo Gallery
|
||||
PhotoViewGallery.builder(
|
||||
scrollPhysics: const BouncingScrollPhysics(),
|
||||
builder: (BuildContext context, int index) {
|
||||
final imageUrl = widget.imageUrls[index];
|
||||
debugPrint("📸 Building image at index $index: $imageUrl");
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
// Ensure UI is restored on back button press
|
||||
SystemChrome.setEnabledSystemUIMode(
|
||||
SystemUiMode.manual,
|
||||
overlays: SystemUiOverlay.values,
|
||||
);
|
||||
return true;
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
// Photo Gallery
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
// Add tap functionality to close when tapping on image
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: PhotoViewGallery.builder(
|
||||
scrollPhysics: const BouncingScrollPhysics(),
|
||||
builder: (BuildContext context, int index) {
|
||||
final imageUrl = widget.imageUrls[index];
|
||||
debugPrint("📸 Building image at index $index: $imageUrl");
|
||||
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: CachedNetworkImageProvider(imageUrl),
|
||||
initialScale: PhotoViewComputedScale.contained,
|
||||
minScale: PhotoViewComputedScale.contained * 0.8,
|
||||
maxScale: PhotoViewComputedScale.covered * 2.0,
|
||||
heroAttributes: PhotoViewHeroAttributes(tag: "photo_$index"),
|
||||
);
|
||||
},
|
||||
itemCount: widget.imageUrls.length,
|
||||
loadingBuilder:
|
||||
(context, event) => Center(
|
||||
child: SizedBox(
|
||||
width: 30.0,
|
||||
height: 30.0,
|
||||
child: CircularProgressIndicator(
|
||||
value:
|
||||
event == null
|
||||
? 0
|
||||
: event.cumulativeBytesLoaded /
|
||||
event.expectedTotalBytes!,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: CachedNetworkImageProvider(imageUrl),
|
||||
initialScale: PhotoViewComputedScale.contained,
|
||||
minScale: PhotoViewComputedScale.contained * 0.8,
|
||||
maxScale: PhotoViewComputedScale.covered * 2.0,
|
||||
heroAttributes: PhotoViewHeroAttributes(
|
||||
tag: "photo_$index",
|
||||
),
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
debugPrint("📸 Error loading image: $error");
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.broken_image_rounded,
|
||||
color: Colors.white70,
|
||||
size: 50,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Gagal memuat gambar',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: widget.imageUrls.length,
|
||||
loadingBuilder:
|
||||
(context, event) => Center(
|
||||
child: Container(
|
||||
width: 40.0,
|
||||
height: 40.0,
|
||||
child: CircularProgressIndicator(
|
||||
value:
|
||||
event == null
|
||||
? 0
|
||||
: event.cumulativeBytesLoaded /
|
||||
(event.expectedTotalBytes ?? 1),
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundDecoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
),
|
||||
pageController: pageController,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
currentIndex = index;
|
||||
debugPrint("📸 Page changed to index: $index");
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Close button
|
||||
Positioned(
|
||||
top: 20,
|
||||
left: 20,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundDecoration: BoxDecoration(color: Colors.black),
|
||||
pageController: pageController,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
currentIndex = index;
|
||||
debugPrint("📸 Page changed to index: $index");
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
// Close button
|
||||
Positioned(
|
||||
top: 40,
|
||||
left: 20,
|
||||
child: IconButton(
|
||||
icon: Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.close, color: Colors.white),
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
),
|
||||
|
||||
// Image counter
|
||||
Positioned(
|
||||
top: 40,
|
||||
right: 20,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
'${currentIndex + 1}/${widget.imageUrls.length}',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
// Image counter
|
||||
Positioned(
|
||||
top: 20,
|
||||
right: 20,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
'${currentIndex + 1}/${widget.imageUrls.length}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -318,7 +318,7 @@
|
||||
Get.snackbar(
|
||||
'Perhatian',
|
||||
'Pilih jam mulai terlebih dahulu',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: AppColors.warning,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
@ -102,25 +102,25 @@ class PembayaranSewaView extends GetView<PembayaranSewaController> {
|
||||
.toUpperCase();
|
||||
final updatedAtStr =
|
||||
controller.orderDetails.value['updated_at'];
|
||||
print('DEBUG status: ' + status);
|
||||
print(
|
||||
'DEBUG updated_at (raw): ' +
|
||||
(updatedAtStr?.toString() ?? 'NULL'),
|
||||
debugPrint('DEBUG status (batas waktu): $status');
|
||||
debugPrint(
|
||||
'DEBUG updated_at batas waktu (raw): ${updatedAtStr?.toString() ?? 'NULL'}',
|
||||
);
|
||||
if (status == 'MENUNGGU PEMBAYARAN' && updatedAtStr != null) {
|
||||
try {
|
||||
final updatedAt = DateTime.parse(updatedAtStr);
|
||||
print(
|
||||
'DEBUG updated_at (parsed): ' +
|
||||
updatedAt.toIso8601String(),
|
||||
debugPrint(
|
||||
'DEBUG updated_at batas waktu (parsed): ${updatedAt.toIso8601String()}',
|
||||
);
|
||||
return CountdownTimerWidget(updatedAt: updatedAt);
|
||||
} catch (e) {
|
||||
print('ERROR parsing updated_at: ' + e.toString());
|
||||
return Text(
|
||||
'Format tanggal salah',
|
||||
style: TextStyle(color: Colors.red),
|
||||
debugPrint('ERROR parsing updated_at batas waktu: $e');
|
||||
// Fallback to current time if parsing fails
|
||||
final now = DateTime.now();
|
||||
debugPrint(
|
||||
'Using current time as fallback for batas waktu: ${now.toIso8601String()}',
|
||||
);
|
||||
return CountdownTimerWidget(updatedAt: now);
|
||||
}
|
||||
}
|
||||
return SizedBox.shrink();
|
||||
@ -322,25 +322,25 @@ class PembayaranSewaView extends GetView<PembayaranSewaController> {
|
||||
.toUpperCase();
|
||||
final updatedAtStr =
|
||||
controller.orderDetails.value['updated_at'];
|
||||
print('DEBUG status: ' + status);
|
||||
print(
|
||||
'DEBUG updated_at (raw): ' +
|
||||
(updatedAtStr?.toString() ?? 'NULL'),
|
||||
debugPrint('DEBUG status (batas waktu): $status');
|
||||
debugPrint(
|
||||
'DEBUG updated_at batas waktu (raw): ${updatedAtStr?.toString() ?? 'NULL'}',
|
||||
);
|
||||
if (status == 'MENUNGGU PEMBAYARAN' && updatedAtStr != null) {
|
||||
try {
|
||||
final updatedAt = DateTime.parse(updatedAtStr);
|
||||
print(
|
||||
'DEBUG updated_at (parsed): ' +
|
||||
updatedAt.toIso8601String(),
|
||||
debugPrint(
|
||||
'DEBUG updated_at batas waktu (parsed): ${updatedAt.toIso8601String()}',
|
||||
);
|
||||
return CountdownTimerWidget(updatedAt: updatedAt);
|
||||
} catch (e) {
|
||||
print('ERROR parsing updated_at: ' + e.toString());
|
||||
return Text(
|
||||
'Format tanggal salah',
|
||||
style: TextStyle(color: Colors.red),
|
||||
debugPrint('ERROR parsing updated_at batas waktu: $e');
|
||||
// Fallback to current time if parsing fails
|
||||
final now = DateTime.now();
|
||||
debugPrint(
|
||||
'Using current time as fallback for batas waktu: ${now.toIso8601String()}',
|
||||
);
|
||||
return CountdownTimerWidget(updatedAt: now);
|
||||
}
|
||||
}
|
||||
return SizedBox.shrink();
|
||||
@ -363,7 +363,7 @@ class PembayaranSewaView extends GetView<PembayaranSewaController> {
|
||||
'step': 0,
|
||||
},
|
||||
{
|
||||
'title': 'Memeriksa Pembayaran',
|
||||
'title': 'Periksa Pembayaran',
|
||||
'description': 'Pembayaran sedang diverifikasi oleh petugas',
|
||||
'icon': Icons.receipt_long,
|
||||
'step': 1,
|
||||
@ -381,8 +381,8 @@ class PembayaranSewaView extends GetView<PembayaranSewaController> {
|
||||
'step': 3,
|
||||
},
|
||||
{
|
||||
'title': 'Pengembalian',
|
||||
'description': 'Proses pengembalian aset sewa',
|
||||
'title': 'Dikembalikan',
|
||||
'description': 'Aset sudah dikembalikan',
|
||||
'icon': Icons.assignment_return,
|
||||
'step': 4,
|
||||
},
|
||||
@ -2585,9 +2585,8 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
print(
|
||||
'DEBUG [CountdownTimerWidget] updatedAt: ' +
|
||||
widget.updatedAt.toIso8601String(),
|
||||
debugPrint(
|
||||
'DEBUG [CountdownTimerWidget] updatedAt: ${widget.updatedAt.toIso8601String()}',
|
||||
);
|
||||
updateRemaining();
|
||||
timer = Timer.periodic(
|
||||
@ -2599,18 +2598,29 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
void updateRemaining() {
|
||||
final now = DateTime.now();
|
||||
final end = widget.updatedAt.add(const Duration(hours: 1));
|
||||
|
||||
debugPrint('Current time: $now');
|
||||
debugPrint('Deadline: $end');
|
||||
|
||||
setState(() {
|
||||
remaining = end.difference(now);
|
||||
debugPrint('Remaining time: ${remaining.inSeconds} seconds');
|
||||
|
||||
if (remaining.isNegative) {
|
||||
debugPrint('Countdown expired, setting to zero');
|
||||
remaining = Duration.zero;
|
||||
timer?.cancel();
|
||||
widget.onTimeout?.call();
|
||||
if (widget.onTimeout != null) {
|
||||
debugPrint('Calling onTimeout callback');
|
||||
widget.onTimeout?.call();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
debugPrint('CountdownTimerWidget disposed');
|
||||
timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
@ -2620,9 +2630,15 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
if (remaining.inSeconds <= 0) {
|
||||
return Text('Waktu habis', style: TextStyle(color: Colors.red));
|
||||
}
|
||||
|
||||
final h = remaining.inHours;
|
||||
final m = remaining.inMinutes % 60;
|
||||
final s = remaining.inSeconds % 60;
|
||||
|
||||
final timeString =
|
||||
'${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}';
|
||||
debugPrint('Rendering countdown: $timeString');
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
@ -2636,7 +2652,7 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
Icon(Icons.timer_outlined, size: 14, color: Colors.red),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Bayar dalam ${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}',
|
||||
'Bayar dalam $timeString',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
@ -1524,7 +1524,7 @@ class SewaAsetView extends GetView<SewaAsetController> {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'ID aset tidak valid',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1754,7 +1754,7 @@ class SewaAsetView extends GetView<SewaAsetController> {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'ID aset tidak valid',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -1801,7 +1801,7 @@ class SewaAsetView extends GetView<SewaAsetController> {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'ID aset tidak valid',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
@ -14,6 +14,19 @@ class WargaDashboardView extends GetView<WargaDashboardController> {
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
|
||||
// Check if coming from login and trigger refresh
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final args = Get.arguments;
|
||||
final bool isFromLogin = args != null && args['from_login'] == true;
|
||||
if (isFromLogin) {
|
||||
// Trigger refresh after UI is built
|
||||
controller.refreshData();
|
||||
print(
|
||||
'WargaDashboardView: Auto-refreshed data due to login navigation',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false, // Prevent back navigation
|
||||
child: WargaLayout(
|
||||
|
@ -80,7 +80,7 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat menyimpan foto profil',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -99,7 +99,7 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat menghapus foto profil',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -124,7 +124,7 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Perubahan berhasil disimpan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -132,7 +132,7 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat menyimpan perubahan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
@ -156,6 +156,9 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
: IconButton(
|
||||
onPressed: () {
|
||||
isEditing.value = true;
|
||||
// Update controllers with current values when entering edit mode
|
||||
nameController.text = controller.userName.value;
|
||||
phoneController.text = controller.userPhone.value;
|
||||
},
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
tooltip: 'Edit Profil',
|
||||
@ -365,14 +368,6 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
} else {
|
||||
// Set avatar deleted flag
|
||||
isAvatarDeleted.value = true;
|
||||
|
||||
Get.snackbar(
|
||||
'Info',
|
||||
'Foto profil akan dihapus setelah menekan Simpan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.orange.shade700,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.delete_outline, size: 16),
|
||||
@ -468,163 +463,242 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
) {
|
||||
return Column(
|
||||
children: [
|
||||
// Section 1: Data Diri
|
||||
// Section 1: Data Diri - Dengan desain yang lebih modern
|
||||
Card(
|
||||
elevation: 4,
|
||||
elevation: 2,
|
||||
shadowColor: AppColors.primary.withOpacity(0.3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.person_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Data Diri',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
if (isEditing) ...[
|
||||
const Spacer(),
|
||||
Text(
|
||||
'Mode Edit',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.orange.shade700,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Colors.white, AppColors.primary.withOpacity(0.05)],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.person_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.edit_note,
|
||||
color: Colors.orange.shade700,
|
||||
size: 18,
|
||||
const SizedBox(width: 14),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Data Diri',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Informasi personal Anda',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (isEditing) ...[
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.shade100,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.edit_note,
|
||||
color: Colors.orange.shade700,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Mode Edit',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.orange.shade700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Email - always read-only
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.email_rounded,
|
||||
title: 'Email',
|
||||
value: controller.userEmail.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Nama Lengkap - editable
|
||||
_buildEditableInfoItem(
|
||||
context,
|
||||
icon: Icons.person_rounded,
|
||||
title: 'Nama Lengkap',
|
||||
value: controller.userName.value,
|
||||
isEditing: isEditing,
|
||||
controller: nameController,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Nomor Telepon - editable
|
||||
_buildEditableInfoItem(
|
||||
context,
|
||||
icon: Icons.phone_rounded,
|
||||
title: 'Nomor Telepon',
|
||||
value: controller.userPhone.value,
|
||||
isEditing: isEditing,
|
||||
controller: phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Email - always read-only
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.email_rounded,
|
||||
title: 'Email',
|
||||
value: controller.userEmail.value,
|
||||
isVerified: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Nama Lengkap - editable
|
||||
_buildEditableInfoItem(
|
||||
context,
|
||||
icon: Icons.person_rounded,
|
||||
title: 'Nama Lengkap',
|
||||
value: controller.userName.value,
|
||||
isEditing: isEditing,
|
||||
controller: nameController,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Nomor Telepon - editable
|
||||
_buildEditableInfoItem(
|
||||
context,
|
||||
icon: Icons.phone_rounded,
|
||||
title: 'Nomor Telepon',
|
||||
value: controller.userPhone.value,
|
||||
isEditing: isEditing,
|
||||
controller: phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Section 2: Informasi Warga
|
||||
// Section 2: Informasi Warga - Dengan desain yang lebih modern
|
||||
Card(
|
||||
elevation: 4,
|
||||
elevation: 2,
|
||||
shadowColor: AppColors.accent.withOpacity(0.3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.badge_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Informasi Warga',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Colors.white, AppColors.accent.withOpacity(0.05)],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.badge_rounded,
|
||||
color: AppColors.accent,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Informasi Warga',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.accent,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Detail kependudukan',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.credit_card_rounded,
|
||||
title: 'NIK',
|
||||
value: controller.userNik.value,
|
||||
isImportant: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.calendar_today_rounded,
|
||||
title: 'Tanggal Lahir',
|
||||
value: formatTanggalLahir(
|
||||
controller.userTanggalLahir.value,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.credit_card_rounded,
|
||||
title: 'NIK',
|
||||
value: controller.userNik.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.calendar_today_rounded,
|
||||
title: 'Tanggal Lahir',
|
||||
value: controller.userTanggalLahir.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.home_rounded,
|
||||
title: 'Alamat',
|
||||
value: controller.userAddress.value,
|
||||
isMultiLine: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.location_on_rounded,
|
||||
title: 'RT/RW',
|
||||
value: controller.userRtRw.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.location_city_rounded,
|
||||
title: 'Kelurahan/Desa',
|
||||
value: controller.userKelurahanDesa.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.map_rounded,
|
||||
title: 'Kecamatan',
|
||||
value: controller.userKecamatan.value,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.home_rounded,
|
||||
title: 'Alamat',
|
||||
value: controller.userAddress.value,
|
||||
isMultiLine: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Tampilkan RT/RW dan Kelurahan/Desa dalam dua baris terpisah
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.location_on_rounded,
|
||||
title: 'RT/RW',
|
||||
value: controller.userRtRw.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.location_city_rounded,
|
||||
title: 'Kelurahan/Desa',
|
||||
value: controller.userKelurahanDesa.value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItemModern(
|
||||
context,
|
||||
icon: Icons.map_rounded,
|
||||
title: 'Kecamatan',
|
||||
value: controller.userKecamatan.value,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -638,46 +712,85 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
required String title,
|
||||
required String value,
|
||||
bool isMultiLine = false,
|
||||
bool isImportant = false,
|
||||
bool isVerified = false,
|
||||
bool isCompact = false,
|
||||
}) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade50,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color:
|
||||
isImportant
|
||||
? AppColors.primary.withOpacity(0.3)
|
||||
: Colors.grey.shade200,
|
||||
width: isImportant ? 1.5 : 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.05),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: isCompact ? 12 : 16,
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
crossAxisAlignment:
|
||||
isMultiLine ? CrossAxisAlignment.start : CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: EdgeInsets.all(isCompact ? 6 : 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
color:
|
||||
isImportant
|
||||
? AppColors.primary.withOpacity(0.15)
|
||||
: AppColors.accent.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, color: AppColors.primary, size: 20),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: isImportant ? AppColors.primary : AppColors.accent,
|
||||
size: isCompact ? 16 : 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: isCompact ? 12 : 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
if (isVerified) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.verified, size: 14, color: Colors.green),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value.isEmpty ? 'Tidak tersedia' : value,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade800,
|
||||
fontSize: isCompact ? 14 : 15,
|
||||
fontWeight: isImportant ? FontWeight.w700 : FontWeight.w600,
|
||||
color:
|
||||
isImportant
|
||||
? AppColors.primary
|
||||
: value.isEmpty
|
||||
? Colors.grey.shade400
|
||||
: Colors.grey.shade800,
|
||||
),
|
||||
maxLines: isMultiLine ? 3 : 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@ -685,6 +798,12 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (isImportant)
|
||||
Icon(
|
||||
Icons.priority_high,
|
||||
size: 16,
|
||||
color: AppColors.primary.withOpacity(0.7),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -821,7 +940,7 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
Get.snackbar(
|
||||
'Info',
|
||||
'Fitur Ubah Password akan segera tersedia',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -933,4 +1052,54 @@ class WargaProfileView extends GetView<WargaDashboardController> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Fungsi untuk memformat tanggal lahir ke format Indonesia
|
||||
String formatTanggalLahir(String tanggal) {
|
||||
if (tanggal.isEmpty) return '';
|
||||
|
||||
try {
|
||||
// Coba parse tanggal dari berbagai format yang mungkin
|
||||
DateTime? dateTime;
|
||||
|
||||
// Coba format yyyy-MM-dd
|
||||
if (tanggal.contains('-')) {
|
||||
final parts = tanggal.split('-');
|
||||
if (parts.length == 3) {
|
||||
dateTime = DateTime.tryParse(tanggal);
|
||||
}
|
||||
}
|
||||
// Coba format dd/MM/yyyy
|
||||
else if (tanggal.contains('/')) {
|
||||
final parts = tanggal.split('/');
|
||||
if (parts.length == 3) {
|
||||
dateTime = DateTime.tryParse('${parts[2]}-${parts[1]}-${parts[0]}');
|
||||
}
|
||||
}
|
||||
|
||||
// Jika tidak bisa parse, kembalikan nilai asli
|
||||
if (dateTime == null) return tanggal;
|
||||
|
||||
// Daftar nama bulan dalam bahasa Indonesia
|
||||
final List<String> namaBulan = [
|
||||
'Januari',
|
||||
'Februari',
|
||||
'Maret',
|
||||
'April',
|
||||
'Mei',
|
||||
'Juni',
|
||||
'Juli',
|
||||
'Agustus',
|
||||
'September',
|
||||
'Oktober',
|
||||
'November',
|
||||
'Desember',
|
||||
];
|
||||
|
||||
// Format tanggal ke format Indonesia: dd Bulan yyyy
|
||||
return '${dateTime.day} ${namaBulan[dateTime.month - 1]} ${dateTime.year}';
|
||||
} catch (e) {
|
||||
// Jika ada error, kembalikan nilai asli
|
||||
return tanggal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -570,8 +570,34 @@ class WargaSewaView extends GetView<WargaSewaController> {
|
||||
if ((rental['status'] ?? '').toString().toUpperCase() ==
|
||||
'MENUNGGU PEMBAYARAN' &&
|
||||
rental['updated_at'] != null)
|
||||
CountdownTimerWidget(
|
||||
updatedAt: DateTime.parse(rental['updated_at']),
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final updatedAtStr = rental['updated_at'];
|
||||
debugPrint('DEBUG status: ${rental['status']}');
|
||||
debugPrint('DEBUG updated_at: $updatedAtStr');
|
||||
|
||||
if (updatedAtStr != null) {
|
||||
try {
|
||||
final updatedAt = DateTime.parse(updatedAtStr);
|
||||
debugPrint(
|
||||
'DEBUG parsed updated_at: ${updatedAt.toIso8601String()}',
|
||||
);
|
||||
return CountdownTimerWidget(
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('ERROR parsing updated_at: $e');
|
||||
return Text(
|
||||
'Format tanggal salah',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 12,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -1856,32 +1882,46 @@ class CountdownTimerWidget extends StatefulWidget {
|
||||
class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
late Duration remaining;
|
||||
Timer? timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
debugPrint(
|
||||
'CountdownTimerWidget initialized with updatedAt: ${widget.updatedAt}',
|
||||
);
|
||||
updateRemaining();
|
||||
timer = Timer.periodic(
|
||||
const Duration(seconds: 1),
|
||||
(_) => updateRemaining(),
|
||||
);
|
||||
print('DEBUG updated_at: ${widget.updatedAt}');
|
||||
}
|
||||
|
||||
void updateRemaining() {
|
||||
final now = DateTime.now();
|
||||
final deadline = widget.updatedAt.add(const Duration(hours: 1));
|
||||
|
||||
debugPrint('Current time: $now');
|
||||
debugPrint('Deadline: $deadline');
|
||||
|
||||
setState(() {
|
||||
remaining = deadline.difference(now);
|
||||
debugPrint('Remaining time: ${remaining.inSeconds} seconds');
|
||||
|
||||
if (remaining.isNegative) {
|
||||
debugPrint('Countdown expired, setting to zero');
|
||||
remaining = Duration.zero;
|
||||
timer?.cancel();
|
||||
widget.onTimeout?.call();
|
||||
if (widget.onTimeout != null) {
|
||||
debugPrint('Calling onTimeout callback');
|
||||
widget.onTimeout?.call();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
debugPrint('CountdownTimerWidget disposed');
|
||||
timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
@ -1891,9 +1931,15 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
if (remaining.inSeconds <= 0) {
|
||||
return Text('Waktu habis', style: TextStyle(color: Colors.red));
|
||||
}
|
||||
|
||||
final h = remaining.inHours;
|
||||
final m = remaining.inMinutes % 60;
|
||||
final s = remaining.inSeconds % 60;
|
||||
|
||||
final timeString =
|
||||
'${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}';
|
||||
debugPrint('Rendering countdown: $timeString');
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
@ -1907,7 +1953,7 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
|
||||
Icon(Icons.timer_outlined, size: 14, color: Colors.red),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Bayar dalam ${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}',
|
||||
'Bayar dalam $timeString',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
Reference in New Issue
Block a user