116 lines
3.8 KiB
Dart
116 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class MiscellaneousListWidget extends StatelessWidget {
|
|
|
|
final List<Map<String,dynamic>> miscellaneousList;
|
|
final Function(bool, Map<String, dynamic>, String) onOpen;
|
|
final Function(Map<String, dynamic>) onDeleteMiscellaneous;
|
|
final Map<String, dynamic>? 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<DataRow> _buildDataRows() {
|
|
print("miscellaneousList - $miscellaneousList");
|
|
List<dynamic> 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<Map<String, dynamic>> 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<String, dynamic> 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();
|
|
}
|
|
}
|