diff --git a/lib/app/modules/petugas_desa/controllers/stok_bantuan_controller.dart b/lib/app/modules/petugas_desa/controllers/stok_bantuan_controller.dart index cc65d9c..ffd698c 100644 --- a/lib/app/modules/petugas_desa/controllers/stok_bantuan_controller.dart +++ b/lib/app/modules/petugas_desa/controllers/stok_bantuan_controller.dart @@ -10,6 +10,7 @@ class StokBantuanController extends GetxController { final SupabaseService _supabaseService = SupabaseService.to; final RxBool isLoading = false.obs; + final RxBool showInfoBanner = true.obs; // Data untuk stok bantuan final RxList daftarStokBantuan = [].obs; @@ -26,6 +27,9 @@ class StokBantuanController extends GetxController { final TextEditingController searchController = TextEditingController(); final RxString searchQuery = ''.obs; + // Filter untuk stok bantuan + final RxString filterValue = 'semua'.obs; + // Tambahkan properti untuk total dana bantuan RxDouble totalDanaBantuan = 0.0.obs; @@ -241,10 +245,30 @@ class StokBantuanController extends GetxController { } List getFilteredStokBantuan() { - if (searchQuery.isEmpty) { - return daftarStokBantuan; - } else { - return daftarStokBantuan + var filteredList = []; + + // Filter berdasarkan jenis (uang/barang/hampir habis) + switch (filterValue.value) { + case 'uang': + filteredList = + daftarStokBantuan.where((item) => item.isUang == true).toList(); + break; + case 'barang': + filteredList = + daftarStokBantuan.where((item) => item.isUang != true).toList(); + break; + case 'hampir_habis': + filteredList = daftarStokBantuan + .where((item) => (item.totalStok ?? 0) <= 10) + .toList(); + break; + default: // 'semua' + filteredList = daftarStokBantuan.toList(); + } + + // Filter berdasarkan pencarian jika ada + if (searchQuery.isNotEmpty) { + return filteredList .where((item) => (item.nama ?.toLowerCase() @@ -260,6 +284,8 @@ class StokBantuanController extends GetxController { false)) .toList(); } + + return filteredList; } // Metode untuk mendapatkan jumlah stok yang hampir habis (stok <= 10) @@ -287,4 +313,9 @@ class StokBantuanController extends GetxController { Future _filterStokBantuan() async { // Implementasi metode _filterStokBantuan } + + // Metode untuk mengatur filter + void setFilter(String value) { + filterValue.value = value; + } } diff --git a/lib/app/modules/petugas_desa/views/stok_bantuan_view.dart b/lib/app/modules/petugas_desa/views/stok_bantuan_view.dart index 3e5e282..7aafe93 100644 --- a/lib/app/modules/petugas_desa/views/stok_bantuan_view.dart +++ b/lib/app/modules/petugas_desa/views/stok_bantuan_view.dart @@ -235,11 +235,38 @@ class StokBantuanView extends GetView { decoration: BoxDecoration( color: Colors.grey.shade100, borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.grey.shade300, width: 1), ), - child: IconButton( - onPressed: controller.refreshData, - icon: const Icon(Icons.refresh), - tooltip: 'Refresh', + padding: const EdgeInsets.symmetric(horizontal: 8), + child: DropdownButtonHideUnderline( + child: DropdownButton( + value: controller.filterValue.value, + icon: const Icon(Icons.filter_list), + hint: const Text('Filter'), + items: [ + DropdownMenuItem( + value: 'semua', + child: Text('Semua'), + ), + DropdownMenuItem( + value: 'uang', + child: Text('Uang'), + ), + DropdownMenuItem( + value: 'barang', + child: Text('Barang'), + ), + DropdownMenuItem( + value: 'hampir_habis', + child: Text('Hampir Habis'), + ), + ], + onChanged: (value) { + if (value != null) { + controller.setFilter(value); + } + }, + ), ), ), ], @@ -261,7 +288,9 @@ class StokBantuanView extends GetView { const SizedBox(height: 16), Text( controller.searchQuery.isEmpty - ? 'Belum ada data stok bantuan' + ? controller.filterValue.value == 'semua' + ? 'Belum ada data stok bantuan' + : 'Tidak ada stok bantuan yang sesuai dengan filter' : 'Tidak ada stok bantuan yang sesuai dengan pencarian', style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center,