| 1 | import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | import 'package:flutter_svg/flutter_svg.dart'; |
| 4 | import 'package:gap/gap.dart'; |
| 5 | import 'package:google_fonts/google_fonts.dart'; |
| 6 | import 'package:openapi/openapi.dart'; |
| 7 | |
| 8 | import 'package:aero/extensions/datetime.dart'; |
| 9 | import 'package:aero/extensions/duration.dart'; |
| 10 | import 'package:aero/formatters/time.dart'; |
| 11 | import 'package:aero/utils/duration.dart'; |
| 12 | |
| 13 | class ShareableFlightCard extends StatelessWidget |
| 14 | const ShareableFlightCard({ |
| 15 | super.key, |
| 16 | required this.info, |
| 17 | }); |
| 18 | |
| 19 | final FlightResponseEntity info; |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext |
| 23 | final departure = info.departure; |
| 24 | final arrival = info.arrival; |
| 25 | final airline = info.airline; |
| 26 | |
| 27 | final departureTime = DateTime. |
| 28 | (departure.revisedTime ?? departure.scheduledTime).utc, |
| 29 | ); |
| 30 | final arrivalTime = DateTime. |
| 31 | (arrival.revisedTime ?? arrival.scheduledTime).utc, |
| 32 | ); |
| 33 | final departureScheduled = DateTime. |
| 34 | final arrivalScheduled = DateTime. |
| 35 | |
| 36 | final departureDelay = departure.revisedTime != |
| 37 | ? departureTime.difference(departureScheduled) |
| 38 | : null; |
| 39 | final arrivalDelay = arrival.revisedTime != |
| 40 | ? arrivalTime.difference(arrivalScheduled) |
| 41 | : null; |
| 42 | |
| 43 | Duration duration; |
| 44 | try { |
| 45 | duration = calculateFlightDuration( |
| 46 | departureTime: departureTime.toIso8601String(), |
| 47 | departureTimezone: departure.airport.timeZone ?? 'UTC' |
| 48 | arrivalTime: arrivalTime.toIso8601String(), |
| 49 | arrivalTimezone: arrival.airport.timeZone ?? 'UTC' |
| 50 | ); |
| 51 | } catch (_) { |
| 52 | duration = arrivalTime.difference(departureTime); |
| 53 | } |
| 54 | |
| 55 | return Container( |
| 56 | width: 450, |
| 57 | height: 600, |
| 58 | decoration: BoxDecoration( |
| 59 | color: const Color( |
| 60 | borderRadius: BorderRadius.circular( |
| 61 | ), |
| 62 | child: Stack( |
| 63 | clipBehavior: Clip.antiAlias, |
| 64 | children: [ |
| 65 | Positioned.fill( |
| 66 | child: Opacity( |
| 67 | opacity: 0.3, |
| 68 | child: SvgPicture.asset( |
| 69 | 'assets/background/world.svg', |
| 70 | fit: BoxFit.cover, |
| 71 | colorFilter: ColorFilter.mode( |
| 72 | Colors.black.withOpacity( |
| 73 | BlendMode.darken, |
| 74 | ), |
| 75 | ), |
| 76 | ), |
| 77 | ), |
| 78 | Positioned.fill( |
| 79 | child: Container( |
| 80 | decoration: BoxDecoration( |
| 81 | gradient: RadialGradient( |
| 82 | center: Alignment.topLeft, |
| 83 | radius: 1.5, |
| 84 | colors: [ |
| 85 | Colors.white.withOpacity( |
| 86 | Colors.white.withOpacity( |
| 87 | Colors.transparent, |
| 88 | ], |
| 89 | stops: const [0.0, |
| 90 | ), |
| 91 | ), |
| 92 | ), |
| 93 | ), |
| 94 | Padding( |
| 95 | padding: const EdgeInsets. |
| 96 | child: Column( |
| 97 | crossAxisAlignment: CrossAxisAlignment.start, |
| 98 | children: [ |
| 99 | Row( |
| 100 | crossAxisAlignment: CrossAxisAlignment.start, |
| 101 | children: [ |
| 102 | if (airline.image != null) |
| 103 | SvgPicture.network( |
| 104 | airline.image!, |
| 105 | width: 32, |
| 106 | height: 32, |
| 107 | ) |
| 108 | else if (airline.iata != null |
| 109 | CachedNetworkImage( |
| 110 | imageUrl: |
| 111 | "https://airlabs.co/img/airline/m/${airline.iata} |
| 112 | width: 32, |
| 113 | height: 32, |
| 114 | errorWidget: (context, url, error) => |
| 115 | const SizedBox.shrink |
| 116 | ), |
| 117 | const Gap(12) |
| 118 | Expanded( |
| 119 | child: Column( |
| 120 | crossAxisAlignment: CrossAxisAlignment.start, |
| 121 | children: [ |
| 122 | Text( |
| 123 | airline.name ?? 'Airline', |
| 124 | style: TextStyle( |
| 125 | fontFamily: "Geist", |
| 126 | fontSize: 20, |
| 127 | fontWeight: FontWeight.bold, |
| 128 | color: Colors.white.withOpacity |
| 129 | ), |
| 130 | ), |
| 131 | Text( |
| 132 | "${info.flightNo} |
| 133 | style: TextStyle( |
| 134 | fontFamily: "Geist", |
| 135 | fontSize: 16, |
| 136 | fontWeight: FontWeight.w600, |
| 137 | color: Colors.white70, |
| 138 | ), |
| 139 | ), |
| 140 | ], |
| 141 | ), |
| 142 | ), |
| 143 | if (info.greatCircleDistance.km != null |
| 144 | Column( |
| 145 | crossAxisAlignment: CrossAxisAlignment.end, |
| 146 | children: [ |
| 147 | Text( |
| 148 | '${double.parse( |
| 149 | style: TextStyle( |
| 150 | fontFamily: "Geist", |
| 151 | fontSize: 15, |
| 152 | fontWeight: FontWeight.bold, |
| 153 | color: Colors.white.withOpacity |
| 154 | ), |
| 155 | ), |
| 156 | const Gap(2) |
| 157 | Text( |
| 158 | '${(double.parse( |
| 159 | style: TextStyle( |
| 160 | fontFamily: "Geist", |
| 161 | fontSize: 12, |
| 162 | color: Colors.grey[400] |
| 163 | ), |
| 164 | ), |
| 165 | ], |
| 166 | ), |
| 167 | ], |
| 168 | ), |
| 169 | const Spacer(), |
| 170 | Row( |
| 171 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 172 | crossAxisAlignment: CrossAxisAlignment.start, |
| 173 | children: [ |
| 174 | Expanded( |
| 175 | child: Column( |
| 176 | crossAxisAlignment: CrossAxisAlignment.start, |
| 177 | children: [ |
| 178 | Text( |
| 179 | 'Departure', |
| 180 | style: TextStyle( |
| 181 | fontFamily: "Geist", |
| 182 | fontSize: 12, |
| 183 | color: Colors.grey[300] |
| 184 | ), |
| 185 | ), |
| 186 | Row( |
| 187 | children: [ |
| 188 | Text( |
| 189 | departure.airport.iata ?? 'N/A', |
| 190 | style: TextStyle( |
| 191 | fontFamily: "Geist", |
| 192 | fontSize: 32, |
| 193 | fontWeight: FontWeight.bold, |
| 194 | color: Colors.white.withOpacity |
| 195 | ), |
| 196 | ), |
| 197 | const Gap(8) |
| 198 | Icon( |
| 199 | Icons.flight_takeoff, |
| 200 | color: Colors.white.withOpacity |
| 201 | size: 24, |
| 202 | ), |
| 203 | ], |
| 204 | ), |
| 205 | Text( |
| 206 | departure.airport.municipalityName ?? 'Unknown', |
| 207 | style: TextStyle( |
| 208 | fontFamily: "Geist", |
| 209 | fontSize: 14, |
| 210 | color: Colors.grey[300] |
| 211 | ), |
| 212 | ), |
| 213 | const Gap(4) |
| 214 | Column( |
| 215 | crossAxisAlignment: CrossAxisAlignment.start, |
| 216 | children: [ |
| 217 | Text( |
| 218 | departureTime.toTimezoneString( |
| 219 | departure.airport.timeZone ?? 'UTC', |
| 220 | use24Hrs: MediaQuery.of(context) |
| 221 | .alwaysUse24HourFormat, |
| 222 | ), |
| 223 | style: TextStyle( |
| 224 | fontFamily: "Geist", |
| 225 | fontSize: 16, |
| 226 | fontWeight: FontWeight.w600, |
| 227 | color: Colors.white.withOpacity |
| 228 | ), |
| 229 | ), |
| 230 | if (departureDelay != null && |
| 231 | departureDelay != Duration.zero) |
| 232 | Text( |
| 233 | departureDelay.isNegative |
| 234 | ? '${departureDelay.abs |
| 235 | : '${departureDelay.toHumanReadable |
| 236 | style: TextStyle( |
| 237 | fontFamily: "Geist", |
| 238 | fontSize: 11, |
| 239 | color: departureDelay.isNegative |
| 240 | ? Colors.green[300] |
| 241 | : Colors.red[300] |
| 242 | fontWeight: FontWeight.w500, |
| 243 | ), |
| 244 | ), |
| 245 | ], |
| 246 | ), |
| 247 | _buildShareableAirportDetails( |
| 248 | terminal: departure.terminal, |
| 249 | gate: info.flightAwareData?.gateOrigin ?? |
| 250 | departure.gate, |
| 251 | baggage: null, |
| 252 | runway: info.flightAwareData?.actualRunwayOff, |
| 253 | alignment: CrossAxisAlignment.start, |
| 254 | ), |
| 255 | ], |
| 256 | ), |
| 257 | ), |
| 258 | Expanded( |
| 259 | child: Column( |
| 260 | crossAxisAlignment: CrossAxisAlignment.end, |
| 261 | children: [ |
| 262 | Text( |
| 263 | 'Arrival', |
| 264 | style: TextStyle( |
| 265 | fontFamily: "Geist", |
| 266 | fontSize: 12, |
| 267 | color: Colors.grey[300] |
| 268 | ), |
| 269 | ), |
| 270 | Row( |
| 271 | mainAxisAlignment: MainAxisAlignment.end, |
| 272 | children: [ |
| 273 | Icon( |
| 274 | Icons.flight_land, |
| 275 | color: Colors.white.withOpacity |
| 276 | size: 24, |
| 277 | ), |
| 278 | const Gap(8) |
| 279 | Text( |
| 280 | arrival.airport.iata ?? 'N/A', |
| 281 | style: TextStyle( |
| 282 | fontFamily: "Geist", |
| 283 | fontSize: 32, |
| 284 | fontWeight: FontWeight.bold, |
| 285 | color: Colors.white.withOpacity |
| 286 | ), |
| 287 | ), |
| 288 | ], |
| 289 | ), |
| 290 | Text( |
| 291 | arrival.airport.municipalityName ?? 'Unknown', |
| 292 | style: TextStyle( |
| 293 | fontFamily: "Geist", |
| 294 | fontSize: 14, |
| 295 | color: Colors.grey[300] |
| 296 | ), |
| 297 | textAlign: TextAlign.right, |
| 298 | ), |
| 299 | const Gap(4) |
| 300 | Column( |
| 301 | crossAxisAlignment: CrossAxisAlignment.end, |
| 302 | children: [ |
| 303 | Text( |
| 304 | arrivalTime.toTimezoneString( |
| 305 | arrival.airport.timeZone ?? 'UTC', |
| 306 | use24Hrs: MediaQuery.of(context) |
| 307 | .alwaysUse24HourFormat, |
| 308 | ), |
| 309 | style: TextStyle( |
| 310 | fontFamily: "Geist", |
| 311 | fontSize: 16, |
| 312 | fontWeight: FontWeight.w600, |
| 313 | color: Colors.white.withOpacity |
| 314 | ), |
| 315 | ), |
| 316 | if (arrivalDelay != null && |
| 317 | arrivalDelay != Duration.zero) |
| 318 | Text( |
| 319 | arrivalDelay.isNegative |
| 320 | ? '${arrivalDelay.abs |
| 321 | : '${arrivalDelay.toHumanReadable |
| 322 | style: TextStyle( |
| 323 | fontFamily: "Geist", |
| 324 | fontSize: 11, |
| 325 | color: arrivalDelay.isNegative |
| 326 | ? Colors.green[300] |
| 327 | : Colors.red[300] |
| 328 | fontWeight: FontWeight.w500, |
| 329 | ), |
| 330 | ), |
| 331 | ], |
| 332 | ), |
| 333 | _buildShareableAirportDetails( |
| 334 | terminal: arrival.terminal, |
| 335 | gate: info.flightAwareData?.gateDestination ?? |
| 336 | arrival.gate, |
| 337 | baggage: info.flightAwareData?.baggageClaim ?? |
| 338 | arrival.baggageBelt, |
| 339 | runway: info.flightAwareData?.actualRunwayOn, |
| 340 | alignment: CrossAxisAlignment.end, |
| 341 | ), |
| 342 | ], |
| 343 | ), |
| 344 | ), |
| 345 | ], |
| 346 | ), |
| 347 | const Spacer(), |
| 348 | Row( |
| 349 | mainAxisAlignment: MainAxisAlignment.spaceAround, |
| 350 | children: [ |
| 351 | _buildShareableDetailItem( |
| 352 | Icons.access_time, |
| 353 | 'Duration', |
| 354 | duration.toHumanReadable(), |
| 355 | ), |
| 356 | _buildShareableDetailItem( |
| 357 | Icons.calendar_today, |
| 358 | 'Date', |
| 359 | formatDayAndMonth(departureTime), |
| 360 | ), |
| 361 | _buildShareableDetailItem( |
| 362 | Icons.flight, |
| 363 | 'Aircraft', |
| 364 | info.aircraft?.model?.split |
| 365 | info.aircraft?.registration ?? |
| 366 | 'N/A', |
| 367 | ), |
| 368 | ], |
| 369 | ), |
| 370 | const Gap(16) |
| 371 | Divider( |
| 372 | color: Colors.grey.shade700 |
| 373 | thickness: 0.5, |
| 374 | ), |
| 375 | const Gap(12) |
| 376 | Row( |
| 377 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 378 | children: [ |
| 379 | Text( |
| 380 | 'Powered by Aero', |
| 381 | style: TextStyle( |
| 382 | fontFamily: "Geist", |
| 383 | fontSize: 11, |
| 384 | color: Colors.grey[500] |
| 385 | fontStyle: FontStyle.italic, |
| 386 | ), |
| 387 | ), |
| 388 | if (info.aircraft?.registration != |
| 389 | Text( |
| 390 | info.aircraft!.registration!, |
| 391 | style: GoogleFonts.jetBrainsMono( |
| 392 | fontSize: 10, |
| 393 | color: Colors.grey[500] |
| 394 | letterSpacing: 1.2, |
| 395 | ), |
| 396 | ), |
| 397 | ], |
| 398 | ), |
| 399 | ], |
| 400 | ), |
| 401 | ), |
| 402 | ], |
| 403 | ), |
| 404 | ); |
| 405 | } |
| 406 | |
| 407 | Widget _buildShareableDetailItem(IconData |
| 408 | return Expanded( |
| 409 | child: Column( |
| 410 | mainAxisSize: MainAxisSize.min, |
| 411 | children: [ |
| 412 | Icon( |
| 413 | icon, |
| 414 | color: Colors.white70, |
| 415 | size: 20, |
| 416 | ), |
| 417 | const Gap(6) |
| 418 | Text( |
| 419 | label, |
| 420 | style: TextStyle( |
| 421 | fontFamily: "Geist", |
| 422 | fontSize: 11, |
| 423 | color: Colors.grey[500] |
| 424 | fontWeight: FontWeight.w500, |
| 425 | ), |
| 426 | ), |
| 427 | const Gap(2) |
| 428 | Text( |
| 429 | value, |
| 430 | style: TextStyle( |
| 431 | fontFamily: "Geist", |
| 432 | fontSize: 13, |
| 433 | fontWeight: FontWeight.w600, |
| 434 | color: Colors.white.withOpacity |
| 435 | ), |
| 436 | textAlign: TextAlign.center, |
| 437 | maxLines: 2, |
| 438 | overflow: TextOverflow.ellipsis, |
| 439 | ), |
| 440 | ], |
| 441 | ), |
| 442 | ); |
| 443 | } |
| 444 | |
| 445 | Widget _buildShareableAirportDetails({ |
| 446 | required String? terminal, |
| 447 | required String? gate, |
| 448 | required String? baggage, |
| 449 | required String? runway, |
| 450 | required CrossAxisAlignment alignment, |
| 451 | }) { |
| 452 | final items = <Widget |
| 453 | |
| 454 | if (terminal != null && terminal. |
| 455 | items.add( |
| 456 | _buildShareableDetailRow( |
| 457 | 'Terminal', |
| 458 | terminal, |
| 459 | alignment: alignment, |
| 460 | ), |
| 461 | ); |
| 462 | } |
| 463 | |
| 464 | if (gate != null && gate. |
| 465 | items.add( |
| 466 | _buildShareableDetailRow( |
| 467 | 'Gate', |
| 468 | gate, |
| 469 | alignment: alignment, |
| 470 | ), |
| 471 | ); |
| 472 | } |
| 473 | |
| 474 | if (baggage != null && baggage. |
| 475 | items.add( |
| 476 | _buildShareableDetailRow( |
| 477 | 'Baggage', |
| 478 | baggage, |
| 479 | alignment: alignment, |
| 480 | ), |
| 481 | ); |
| 482 | } |
| 483 | |
| 484 | if (runway != null && runway. |
| 485 | items.add( |
| 486 | _buildShareableDetailRow( |
| 487 | 'Runway', |
| 488 | runway, |
| 489 | alignment: alignment, |
| 490 | ), |
| 491 | ); |
| 492 | } |
| 493 | |
| 494 | if (items.isEmpty) { |
| 495 | return const SizedBox |
| 496 | } |
| 497 | |
| 498 | return Column( |
| 499 | crossAxisAlignment: alignment, |
| 500 | children: items, |
| 501 | ); |
| 502 | } |
| 503 | |
| 504 | Widget _buildShareableDetailRow( |
| 505 | String label, |
| 506 | String value, { |
| 507 | required CrossAxisAlignment alignment, |
| 508 | }) { |
| 509 | return Padding( |
| 510 | padding: const EdgeInsets. |
| 511 | child: Row( |
| 512 | mainAxisSize: MainAxisSize.min, |
| 513 | children: [ |
| 514 | Text( |
| 515 | '$label: ', |
| 516 | style: TextStyle( |
| 517 | fontFamily: "Geist", |
| 518 | fontSize: 10, |
| 519 | color: Colors.white.withOpacity |
| 520 | fontWeight: FontWeight.w600, |
| 521 | ), |
| 522 | ), |
| 523 | Text( |
| 524 | value, |
| 525 | style: TextStyle( |
| 526 | fontFamily: "Geist", |
| 527 | fontSize: 10, |
| 528 | color: Colors.white70, |
| 529 | fontWeight: FontWeight.w600, |
| 530 | ), |
| 531 | ), |
| 532 | ], |
| 533 | ), |
| 534 | ); |
| 535 | } |
| 536 | } |