import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; class ForexListWidget extends StatelessWidget{ final List> forexList; final Function(bool, Map, String)onOpen; final Function(Map) onDeleteForex; final List? apiCountryData; const ForexListWidget({super.key, required this.forexList, required this.onOpen, required this.onDeleteForex,required this.apiCountryData}); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Forex List", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 16), Container( // color: Colors.blueGrey, width: double.infinity, child: Center( child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Expanded( 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('Forex Start Date')), DataColumn(label: Text('Forex End Date')), DataColumn(label: Text('Country')), DataColumn(label: Text('Perdiem Amount')), DataColumn(label: Text('Actions')), ], rows: _buildDataRows(), ), ), ), ), ), ), ], ), ); } List _buildDataRows() { List countryList = apiCountryData ?? []; List> filteredList = forexList .where((item) => item["is_active"] == "1") .toList(); print("filteredList- $filteredList"); 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) { Map item = entry.value; return DataRow(cells: [ // DataCell(Text(item["indx"]?.toString() ?? "N/A")), // Index column DataCell(Text(item["start_date"] ?? "N/A")), DataCell(Text(item["end_date"] ?? "N/A")), DataCell( Text(getRequestForCountry( item["country_code"]!.toString()))), // DataCell(Text(item["country_code"] ?? "N/A")), DataCell(Text(item["perdiem_amount"] ?? "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, "Forex"); }, ), IconButton( icon: Icon(Icons.delete, color: Colors.red), onPressed: () { onDeleteForex(item); }, ), ], )), ]); }).toList(); } }