| 1 | import 'package:built_collection/built_collection.dart'; |
| 2 | import 'package:cached_network_image/cached_network_image.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; |
| 5 | import 'package:openapi/openapi.dart'; |
| 6 | import 'package:aero/formatters/time.dart'; |
| 7 | |
| 8 | class FlightsList extends StatelessWidget |
| 9 | final BuiltList<FlightEntity |
| 10 | final DateTime? selectedDate; |
| 11 | final Function(String |
| 12 | |
| 13 | const FlightsList({ |
| 14 | super.key, |
| 15 | required this.flights, |
| 16 | required this.selectedDate, |
| 17 | required this.onFlightTap, |
| 18 | }); |
| 19 | |
| 20 | @override |
| 21 | Widget build(BuildContext |
| 22 | if (flights.isEmpty || selectedDate == null |
| 23 | return SizedBox.shrink |
| 24 | } |
| 25 | |
| 26 | return ListView.separated |
| 27 | separatorBuilder: (context, index) { |
| 28 | return Divider( |
| 29 | height: 1, |
| 30 | thickness: 0.5, |
| 31 | color: Colors.grey.withOpacity |
| 32 | ); |
| 33 | }, |
| 34 | itemBuilder: (context, index) { |
| 35 | final flight = flights[index]; |
| 36 | final arrivalTime = DateTime. |
| 37 | final departureTime = DateTime. |
| 38 | final currentTime = DateTime. |
| 39 | return InkWell( |
| 40 | onTap: () => onFlightTap( |
| 41 | flight.flight.iataNumber, |
| 42 | flight.flight.icaoNumber, |
| 43 | selectedDate!, |
| 44 | ), |
| 45 | child: Padding( |
| 46 | padding: const EdgeInsets. |
| 47 | vertical: 4, |
| 48 | horizontal: 4.0, |
| 49 | ), |
| 50 | child: Row( |
| 51 | crossAxisAlignment: CrossAxisAlignment.center, |
| 52 | children: [ |
| 53 | Container( |
| 54 | width: 48, |
| 55 | height: 48, |
| 56 | decoration: BoxDecoration( |
| 57 | borderRadius: BorderRadius.circular( |
| 58 | ), |
| 59 | padding: EdgeInsets.all( |
| 60 | child: CachedNetworkImage( |
| 61 | imageUrl: |
| 62 | "https://airlabs.co/img/airline/m/${flight.airline. |
| 63 | fit: BoxFit.contain, |
| 64 | errorWidget: (context, url, error) { |
| 65 | return Icon( |
| 66 | MdiIcons.airplane, |
| 67 | size: 24, |
| 68 | color: Colors.grey, |
| 69 | ); |
| 70 | }, |
| 71 | ), |
| 72 | ), |
| 73 | SizedBox(width: 12), |
| 74 | Expanded( |
| 75 | child: Column( |
| 76 | crossAxisAlignment: CrossAxisAlignment.start, |
| 77 | mainAxisAlignment: MainAxisAlignment.center, |
| 78 | children: [ |
| 79 | Text( |
| 80 | flight.airline.name, |
| 81 | style: TextStyle( |
| 82 | fontWeight: FontWeight.bold, |
| 83 | fontSize: 14, |
| 84 | ), |
| 85 | overflow: TextOverflow.ellipsis, |
| 86 | ), |
| 87 | SizedBox(height: 2), |
| 88 | Text( |
| 89 | "${flight.flight. |
| 90 | style: TextStyle( |
| 91 | fontSize: 12, |
| 92 | color: Colors.grey[600] |
| 93 | ), |
| 94 | ), |
| 95 | ], |
| 96 | ), |
| 97 | ), |
| 98 | Column( |
| 99 | crossAxisAlignment: CrossAxisAlignment.end, |
| 100 | mainAxisAlignment: MainAxisAlignment.center, |
| 101 | children: [ |
| 102 | Row( |
| 103 | mainAxisSize: MainAxisSize.min, |
| 104 | children: [ |
| 105 | Text( |
| 106 | "${flight.departure. |
| 107 | style: TextStyle( |
| 108 | fontSize: 12, |
| 109 | ), |
| 110 | ), |
| 111 | Text( |
| 112 | formatTime( |
| 113 | departureTime, |
| 114 | use24HourFormat: MediaQuery.of(context) |
| 115 | .alwaysUse24HourFormat, |
| 116 | ), |
| 117 | style: TextStyle( |
| 118 | fontSize: 13, |
| 119 | color: currentTime.isAfter(departureTime) |
| 120 | ? Colors.red |
| 121 | : Colors.green, |
| 122 | fontWeight: FontWeight.bold, |
| 123 | ), |
| 124 | ), |
| 125 | ], |
| 126 | ), |
| 127 | SizedBox(height: 6), |
| 128 | Row( |
| 129 | mainAxisSize: MainAxisSize.min, |
| 130 | children: [ |
| 131 | Text( |
| 132 | "${flight.arrival. |
| 133 | style: TextStyle( |
| 134 | fontSize: 12, |
| 135 | ), |
| 136 | ), |
| 137 | Text( |
| 138 | formatTime( |
| 139 | arrivalTime, |
| 140 | use24HourFormat: |
| 141 | MediaQuery.of(context).alwaysUse24HourFormat |
| 142 | ), |
| 143 | style: TextStyle( |
| 144 | fontSize: 13, |
| 145 | color: currentTime.isAfter(arrivalTime) |
| 146 | ? Colors.red |
| 147 | : Colors.green, |
| 148 | fontWeight: FontWeight.bold, |
| 149 | ), |
| 150 | ), |
| 151 | ], |
| 152 | ), |
| 153 | ], |
| 154 | ), |
| 155 | ], |
| 156 | ), |
| 157 | ), |
| 158 | ); |
| 159 | }, |
| 160 | shrinkWrap: true, |
| 161 | padding: EdgeInsets.zero, |
| 162 | itemCount: flights.length, |
| 163 | physics: NeverScrollableScrollPhysics(), |
| 164 | ); |
| 165 | } |
| 166 | } |
| 167 | |