| 1 | import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | import 'package:flutter_svg/svg.dart'; |
| 4 | import 'package:openapi/openapi.dart'; |
| 5 | import 'package:skeletonizer/skeletonizer.dart'; |
| 6 | |
| 7 | class SearchResultsList extends StatelessWidget |
| 8 | final List<Object |
| 9 | final bool loading; |
| 10 | final AirlineEntity? selectedAirline; |
| 11 | final String? selectedFlightNumber; |
| 12 | final TextEditingController flightController; |
| 13 | final Function(AirportEntity |
| 14 | final Function(AirlineEntity |
| 15 | final Function(String |
| 16 | |
| 17 | const SearchResultsList({ |
| 18 | super.key, |
| 19 | required this.results, |
| 20 | required this.loading, |
| 21 | required this.selectedAirline, |
| 22 | required this.selectedFlightNumber, |
| 23 | required this.flightController, |
| 24 | required this.onAirportSelected, |
| 25 | required this.onAirlineSelected, |
| 26 | required this.onFlightNumberSelected, |
| 27 | }); |
| 28 | |
| 29 | @override |
| 30 | Widget build(BuildContext |
| 31 | if (selectedAirline != null) { |
| 32 | return SizedBox.shrink |
| 33 | } |
| 34 | |
| 35 | if (loading && results.isEmpty) { |
| 36 | return Skeletonizer( |
| 37 | child: ListView.builder( |
| 38 | itemBuilder: (context, index) { |
| 39 | final item = index == 0 |
| 40 | ? AirportEntity((b) { |
| 41 | b |
| 42 | ..id = "" |
| 43 | ..ident = "VIDP" |
| 44 | ..isoCountry = "IN" |
| 45 | ..lat = '0' |
| 46 | ..long = '0' |
| 47 | ..name = "Indira Gandhi International Airport" |
| 48 | ..type = AirportType.largeAirport |
| 49 | ..continent = "IDK" |
| 50 | ..isoRegion = "DEL" |
| 51 | ..build(); |
| 52 | }) |
| 53 | : AirlineEntity((b) { |
| 54 | b |
| 55 | ..id = "" |
| 56 | ..iata = "IC" |
| 57 | ..icao = "ICE" |
| 58 | ..name = "Air India" |
| 59 | ..build(); |
| 60 | }); |
| 61 | if (index == 0) { |
| 62 | final airport = item as AirportEntity |
| 63 | return ListTile( |
| 64 | title: Text(airport.name), |
| 65 | leading: Container( |
| 66 | width: 30, |
| 67 | height: 30, |
| 68 | color: Colors.green, |
| 69 | ), |
| 70 | ); |
| 71 | } else { |
| 72 | final airline = item as AirlineEntity |
| 73 | return ListTile( |
| 74 | title: Text(airline.name), |
| 75 | leading: Container( |
| 76 | width: 24, |
| 77 | height: 18, |
| 78 | color: Colors.green, |
| 79 | ), |
| 80 | ); |
| 81 | } |
| 82 | }, |
| 83 | shrinkWrap: true, |
| 84 | physics: NeverScrollableScrollPhysics(), |
| 85 | padding: EdgeInsets.zero, |
| 86 | itemCount: 2, |
| 87 | ), |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | if (selectedAirline != null && |
| 92 | flightController.text.isNotEmpty && |
| 93 | selectedFlightNumber == null) { |
| 94 | return ListTile( |
| 95 | title: Text(selectedAirline!.name) |
| 96 | subtitle: Text( |
| 97 | "${selectedAirline!.iata}${ |
| 98 | ), |
| 99 | leading: selectedAirline!.image != null |
| 100 | selectedAirline!.image!.isNotEmpty |
| 101 | ? SvgPicture.network( |
| 102 | selectedAirline!.image!, |
| 103 | width: 24, |
| 104 | height: 18, |
| 105 | ) |
| 106 | : CachedNetworkImage( |
| 107 | imageUrl: |
| 108 | "https://airlabs.co/img/airline/m/${selectedAirline!.iata} |
| 109 | width: 24, |
| 110 | height: 18, |
| 111 | errorWidget: (context, url, error) { |
| 112 | return SizedBox( |
| 113 | height: 0, |
| 114 | width: 0, |
| 115 | ); |
| 116 | }, |
| 117 | ), |
| 118 | onTap: () => onFlightNumberSelected(flightController. |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | return ListView.builder |
| 123 | padding: EdgeInsets.zero, |
| 124 | shrinkWrap: true, |
| 125 | itemBuilder: (context, index) { |
| 126 | final _item = results[index]; |
| 127 | final runtimeType = _item.runtimeType. |
| 128 | if (runtimeType == '_\$AirportEntity') { |
| 129 | final airport = _item as AirportEntity |
| 130 | return ListTile( |
| 131 | title: Text(airport.name), |
| 132 | subtitle: Text( |
| 133 | "${airport.iataCode != |
| 134 | ), |
| 135 | leading: CachedNetworkImage( |
| 136 | imageUrl: |
| 137 | "https://flagcdn.com/h40/${airport.isoCountry. |
| 138 | width: 30, |
| 139 | height: 30, |
| 140 | errorWidget: (context, url, error) { |
| 141 | return SizedBox( |
| 142 | height: 0, |
| 143 | width: 0, |
| 144 | ); |
| 145 | }, |
| 146 | ), |
| 147 | onTap: () => onAirportSelected(airport), |
| 148 | ); |
| 149 | } else { |
| 150 | final airline = _item as AirlineEntity |
| 151 | return ListTile( |
| 152 | title: Text(airline.name), |
| 153 | subtitle: Text("${airline |
| 154 | leading: airline.image != null && |
| 155 | ? SvgPicture.network( |
| 156 | airline.image!, |
| 157 | width: 24, |
| 158 | height: 18, |
| 159 | ) |
| 160 | : CachedNetworkImage( |
| 161 | imageUrl: |
| 162 | "https://airlabs.co/img/airline/m/${airline.iata} |
| 163 | width: 24, |
| 164 | height: 18, |
| 165 | errorWidget: (context, url, error) { |
| 166 | return SizedBox( |
| 167 | height: 0, |
| 168 | width: 0, |
| 169 | ); |
| 170 | }, |
| 171 | ), |
| 172 | onTap: () => onAirlineSelected(airline), |
| 173 | ); |
| 174 | } |
| 175 | }, |
| 176 | itemCount: results.length, |
| 177 | physics: NeverScrollableScrollPhysics(), |
| 178 | ); |
| 179 | } |
| 180 | } |
| 181 | |