| 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:flutter_svg/svg.dart'; |
| 5 | import 'package:intl/intl.dart'; |
| 6 | import 'package:openapi/openapi.dart'; |
| 7 | |
| 8 | class TrackedFlightsList extends StatelessWidget |
| 9 | final BuiltList<FlightResponseEntity |
| 10 | final Function(String |
| 11 | |
| 12 | const TrackedFlightsList({ |
| 13 | super.key, |
| 14 | required this.trackedFlights, |
| 15 | required this.onFlightTap, |
| 16 | }); |
| 17 | |
| 18 | @override |
| 19 | Widget build(BuildContext |
| 20 | if (trackedFlights.isEmpty) { |
| 21 | return SizedBox.shrink |
| 22 | } |
| 23 | |
| 24 | return Column( |
| 25 | crossAxisAlignment: CrossAxisAlignment.start, |
| 26 | children: [ |
| 27 | Padding( |
| 28 | padding: const EdgeInsets. |
| 29 | horizontal: 8.0, |
| 30 | vertical: 12.0, |
| 31 | ), |
| 32 | child: Text( |
| 33 | "Recently Tracked", |
| 34 | style: TextStyle( |
| 35 | fontSize: 16, |
| 36 | fontWeight: FontWeight.bold, |
| 37 | color: Colors.grey[700] |
| 38 | ), |
| 39 | ), |
| 40 | ), |
| 41 | ListView.separated( |
| 42 | separatorBuilder: (context, index) { |
| 43 | return Divider( |
| 44 | height: 1, |
| 45 | thickness: 0.5, |
| 46 | color: Colors.grey.withOpacity |
| 47 | ); |
| 48 | }, |
| 49 | itemBuilder: (context, index) { |
| 50 | final flight = trackedFlights[index]; |
| 51 | // Convert UTC date to device's local time |
| 52 | final localDate = flight.date. |
| 53 | return InkWell( |
| 54 | onTap: () => onFlightTap( |
| 55 | flight.flightNo, |
| 56 | flight.flightNo, |
| 57 | localDate, |
| 58 | true, |
| 59 | ), |
| 60 | child: Padding( |
| 61 | padding: const EdgeInsets. |
| 62 | vertical: 4, |
| 63 | horizontal: 4.0, |
| 64 | ), |
| 65 | child: Row( |
| 66 | crossAxisAlignment: CrossAxisAlignment.center, |
| 67 | children: [ |
| 68 | Container( |
| 69 | width: 48, |
| 70 | height: 48, |
| 71 | decoration: BoxDecoration( |
| 72 | borderRadius: BorderRadius.circular( |
| 73 | ), |
| 74 | padding: EdgeInsets.all( |
| 75 | child: flight.airline.image != null |
| 76 | ? SvgPicture.network( |
| 77 | flight.airline.image!, |
| 78 | width: 24, |
| 79 | height: 18, |
| 80 | ) |
| 81 | : CachedNetworkImage( |
| 82 | imageUrl: |
| 83 | "https://airlabs.co/img/airline/m/${flight.airline. |
| 84 | fit: BoxFit.contain, |
| 85 | errorWidget: (context, url, error) { |
| 86 | return Icon( |
| 87 | Icons.airplanemode_active, |
| 88 | size: 24, |
| 89 | color: Colors.grey, |
| 90 | ); |
| 91 | }, |
| 92 | ), |
| 93 | ), |
| 94 | SizedBox(width: 12), |
| 95 | Expanded( |
| 96 | child: Column( |
| 97 | crossAxisAlignment: CrossAxisAlignment.start, |
| 98 | mainAxisAlignment: MainAxisAlignment.center, |
| 99 | children: [ |
| 100 | Text( |
| 101 | "${flight.departure. |
| 102 | style: TextStyle( |
| 103 | fontWeight: FontWeight.bold, |
| 104 | fontSize: 15, |
| 105 | ), |
| 106 | ), |
| 107 | SizedBox(height: 4), |
| 108 | Text( |
| 109 | "${flight.departure. |
| 110 | style: TextStyle( |
| 111 | fontSize: 12, |
| 112 | color: Colors.grey[600] |
| 113 | ), |
| 114 | overflow: TextOverflow.ellipsis, |
| 115 | ), |
| 116 | ], |
| 117 | ), |
| 118 | ), |
| 119 | Column( |
| 120 | crossAxisAlignment: CrossAxisAlignment.end, |
| 121 | mainAxisAlignment: MainAxisAlignment.center, |
| 122 | children: [ |
| 123 | Text( |
| 124 | DateFormat('dd MMM yyyy').format |
| 125 | style: TextStyle( |
| 126 | fontSize: 13, |
| 127 | fontWeight: FontWeight.w600, |
| 128 | ), |
| 129 | ), |
| 130 | SizedBox(height: 4), |
| 131 | Text( |
| 132 | flight.flightAwareData != null |
| 133 | ? "${flight.flightAwareData |
| 134 | : flight.flightNo, |
| 135 | style: TextStyle( |
| 136 | fontSize: 12, |
| 137 | color: Colors.grey[600] |
| 138 | ), |
| 139 | ), |
| 140 | ], |
| 141 | ), |
| 142 | ], |
| 143 | ), |
| 144 | ), |
| 145 | ); |
| 146 | }, |
| 147 | |
| 148 | shrinkWrap: true, |
| 149 | padding: EdgeInsets.zero, |
| 150 | itemCount: trackedFlights.length, |
| 151 | physics: NeverScrollableScrollPhysics(), |
| 152 | ), |
| 153 | ], |
| 154 | ); |
| 155 | } |
| 156 | } |
| 157 | |