import 'package:flutter/material.dart'; class TrainListWidget extends StatelessWidget { final List> trainList; final Function(bool, Map, String) onOpen; final Function(Map) onDeleteTrain; const TrainListWidget({super.key, required this.trainList, required this.onOpen, required this.onDeleteTrain}); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(16.0), child: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( "Train 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('Train Number')), // DataColumn(label: Text('Class')), DataColumn(label: Text('From')), // DataColumn(label: Text('To')), DataColumn(label: Text('Actions')), ], rows: _buildDataRows(), ), ), ), ), ], ), ), ); } List _buildDataRows() { List> filteredList = trainList .where((item) => item["is_active"] == "1") .toList(); print("filteredList- $filteredList"); return filteredList.asMap().entries.map((entry) { final Map item = entry.value; return DataRow(cells: [ // DataCell(Text(item["indx"]?.toString() ?? "N/A")), DataCell(Text(item["train_no"]!)), // DataCell(Text(item["class"]!)), DataCell(Text(item["from_station"]!)), // DataCell(Text(item["to_station"]!)), 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, "Train"); }, ), IconButton( icon: Icon(Icons.delete, color: Colors.red), onPressed: () { onDeleteTrain(item); }, ), ], )), ]); }).toList(); } }