111 lines
3.6 KiB
Dart
111 lines
3.6 KiB
Dart
import 'dart:js_interop';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class InsuranceListWidget extends StatelessWidget {
|
|
final List<Map<String,dynamic>> insuranceList;
|
|
final Function(bool, Map<String,dynamic>, String)onOpen;
|
|
final Function(Map<String,dynamic>)onDeleteInsurance;
|
|
final Map<String, dynamic>? apiData;
|
|
const InsuranceListWidget({super.key, required this.insuranceList, required this.onOpen,required this.apiData,
|
|
required this.onDeleteInsurance});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Container(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
"Insurance 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('Insurance Type')),
|
|
DataColumn(label: Text('Start Date')),
|
|
DataColumn(label: Text('End Date')),
|
|
DataColumn(label: Text('Actions')),
|
|
],
|
|
rows: _buildDataRows(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<DataRow> _buildDataRows() {
|
|
|
|
|
|
List<Map<String, dynamic>> filteredList = insuranceList
|
|
.where((item) => item["is_active"] == "1")
|
|
.toList();
|
|
print("filteredList- $filteredList");
|
|
|
|
List<dynamic> insurancetypeList = apiData?['insurance_type_of_insurance'] ?? [];
|
|
|
|
|
|
String getRequestForInsuranceType(String? specialRequestKey) {
|
|
if (specialRequestKey == null) return "N/A";
|
|
|
|
return insurancetypeList
|
|
.firstWhere(
|
|
(element) => element["dropdown_key"].toString() == specialRequestKey,
|
|
orElse: () => {"dropdown_value": "N/A"},
|
|
)["dropdown_value"]
|
|
.toString();
|
|
}
|
|
|
|
return filteredList.asMap().entries.map((entry) {
|
|
|
|
Map<String,dynamic> item = entry.value;
|
|
return DataRow(cells: [
|
|
// DataCell(Text(item["indx"]?.toString() ?? "N/A")), // Index column
|
|
// DataCell(Text(item["type_of_insurance"]!)),
|
|
DataCell( Text(getRequestForInsuranceType( item["type_of_insurance"]!.toString()))),
|
|
DataCell(Text(item["start_date"]!)),
|
|
DataCell(Text(item["end_date"]!)),
|
|
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, "Insurance");
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.delete, color: Colors.red),
|
|
onPressed: () {
|
|
onDeleteInsurance(item);
|
|
},
|
|
),
|
|
],
|
|
)),
|
|
]);
|
|
}).toList();
|
|
}
|
|
}
|