ts-tat/lib/Screens/itnerary_list/visa_list.dart
2025-03-28 18:03:15 +05:30

125 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
class VisaListWidget extends StatelessWidget {
final List<Map<String, dynamic>> visaList;
final Function(bool, Map<String, dynamic>, String) onOpen;
final Function(Map<String, dynamic>) onDeleteMiscellaneous;
final Map<String, dynamic>? apiData;
final List<dynamic>? apiCountryData;
const VisaListWidget({super.key, required this.visaList, required this.onOpen,
required this.onDeleteMiscellaneous, required this.apiData, required this.apiCountryData});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
"Visa 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('Type of Visa')),
DataColumn(label: Text('Country')),
DataColumn(label: Text('Start Date')),
DataColumn(label: Text('Actions')),
],
rows: _buildDataRows(),
),
),
),
),
],
),
),
);
}
List<DataRow> _buildDataRows() {
List<Map<String, dynamic>> filteredList = visaList
.where((item) => item["is_active"] == "1")
.toList();
print("filteredList- $filteredList");
List<dynamic> visatypeList = apiData?['visa_type_of_visa'] ?? [];
List<dynamic> countryList = apiCountryData ?? [];
String getRequestForVisa(String? specialRequestKey) {
if (specialRequestKey == null) return "N/A";
return visatypeList
.firstWhere(
(element) => element["dropdown_key"].toString() == specialRequestKey,
orElse: () => {"dropdown_value": "N/A"},
)["dropdown_value"]
.toString();
}
String getRequestForCountry(String? countryCode) {
if (countryCode == null) return "N/A";
return countryList
.firstWhere(
(element) => element["country_code"].toString() == countryCode,
orElse: () => {"country_name": "N/A"},
)["country_name"]
.toString();
}
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")),
// DataCell(Text(item["type_of_visa"]!)),
DataCell( Text(getRequestForVisa( item["type_of_visa"]!.toString()))),
DataCell( Text(getRequestForCountry( item["country_code"]!.toString()))),
// DataCell(Text(item["country_code"]!)),
DataCell(Text(item["start_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, "Visa");
},
),
IconButton(
icon: Icon(Icons.delete, color: Colors.red),
onPressed: () {
onDeleteMiscellaneous(item);
},
),
],
)),
]);
}).toList();
}
}