import 'package:flutter/material.dart'; class MiscellaneousListWidget extends StatelessWidget { final List> miscellaneousList; final Function(bool, Map, String) onOpen; final Function(Map) onDeleteMiscellaneous; final Map? apiData; const MiscellaneousListWidget({super.key, required this.miscellaneousList, required this.onOpen, required this.onDeleteMiscellaneous,required this.apiData}); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(16.0), child: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( "Miscellaneous Booking List", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 16), Center( child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: SizedBox( width: MediaQuery.of(context).size.width , child: DataTable( border: TableBorder( bottom: BorderSide(color: Colors.black12), horizontalInside: BorderSide(color: Colors.black12), // Only horizontal lines ), columns: const [ // DataColumn(label: Text('#')), DataColumn(label: Text('Special Request')), DataColumn(label: Text('Comments')), // DataColumn(label: Text('Created On')), DataColumn(label: Text('Actions')), ], rows: _buildDataRows(), ), ), ), ), ], ), ), ); } List _buildDataRows() { print("miscellaneousList - $miscellaneousList"); List purposeList = apiData?['miscellaneous_special_request'] ?? []; print("purposeList - $purposeList"); String getRequestValue(String? specialRequestKey) { if (specialRequestKey == null) return "N/A"; return purposeList .firstWhere( (element) => element["dropdown_key"].toString() == specialRequestKey, orElse: () => {"dropdown_value": "N/A"}, )["dropdown_value"] .toString(); } List> filteredList = miscellaneousList .where((item) => item["is_active"] == "1") .toList(); print("filteredList- $filteredList"); return filteredList.asMap().entries.map( (entry) { int index = entry.key + 1; // To start index from 1 Map item = entry.value; print(item); return DataRow(cells: [ // DataCell(Text(item["indx"]?.toString() ?? "N/A")), // Index column // DataCell(Text(specialRequestValue)), DataCell(Text(getRequestValue(item["special_request"]?.toString()))), DataCell(Text(item["comments"] ?? "N/A")), // DataCell(Text(item["created_on"] ?? "N/A")), DataCell(Row( children: [ IconButton( icon: Icon(Icons.remove_red_eye, color: Colors.blue), onPressed: () { // View action }, ), IconButton( icon: Icon(Icons.edit, color: Colors.green), onPressed: () { onOpen(true, item, "Miscellaneous"); // Edit action }, ), IconButton( icon: Icon(Icons.delete, color: Colors.red), onPressed: () { onDeleteMiscellaneous(item); // Delete action }, ), ], )), ]); }).toList(); } }