| 1 | import 'dart:io'; |
| 2 | import 'package:built_collection/built_collection.dart'; |
| 3 | import 'package:cached_network_image/cached_network_image.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter/services.dart'; |
| 6 | import 'package:gap/gap.dart'; |
| 7 | import 'package:material_symbols_icons/symbols.dart'; |
| 8 | import 'package:onesignal_flutter/onesignal_flutter.dart'; |
| 9 | import 'package:openapi/openapi.dart'; |
| 10 | import 'package:aero/constants/main.dart'; |
| 11 | import 'package:aero/services/alerts_service.dart'; |
| 12 | import 'package:aero/utils/error.dart'; |
| 13 | import 'package:aero/extensions/datetime.dart'; |
| 14 | import 'package:aero/formatters/time.dart'; |
| 15 | import 'package:aero/screens/home/widgets/flight_route_info.dart'; |
| 16 | import 'package:aero/screens/home/widgets/shareable_flight_card.dart'; |
| 17 | import 'package:timezone/timezone.dart' as tz; |
| 18 | import 'package:timezone/data/latest.dart' as tz; |
| 19 | import 'package:screenshot/screenshot.dart'; |
| 20 | import 'package:share_plus/share_plus.dart'; |
| 21 | import 'package:path_provider/path_provider.dart'; |
| 22 | |
| 23 | class FlightInfoWidget extends StatefulWidget |
| 24 | final FlightResponseEntity info; |
| 25 | final Function() onClose; |
| 26 | final Function()? onRefreshTracking |
| 27 | final Function()? onRefreshFlightData |
| 28 | final Function()? onBookingDetails |
| 29 | final BuiltList<FlightPositionEntity |
| 30 | const FlightInfoWidget({ |
| 31 | super.key, |
| 32 | required this.info, |
| 33 | required this.onClose, |
| 34 | this.onRefreshTracking, |
| 35 | this.onRefreshFlightData, |
| 36 | this.onBookingDetails, |
| 37 | required this.flightPositions, |
| 38 | }); |
| 39 | |
| 40 | @override |
| 41 | State<FlightInfoWidget> createState |
| 42 | } |
| 43 | |
| 44 | class _FlightInfoWidgetState extends State |
| 45 | bool _showAircraftPayload = false; |
| 46 | final ScreenshotController _screenshotController = |
| 47 | |
| 48 | String _formatKey(String |
| 49 | final withSpaces = key |
| 50 | .replaceAll('_', ' ' |
| 51 | .replaceAllMapped(RegExp(r'(?<!^)([A-Z0-9])' |
| 52 | final parts = withSpaces.split |
| 53 | return parts |
| 54 | .map((w) => w.isEmpty |
| 55 | ? w |
| 56 | : '${w[0 |
| 57 | .join(' '); |
| 58 | } |
| 59 | |
| 60 | String _formatEnumName(String |
| 61 | return enumName |
| 62 | .split('_') |
| 63 | .map((word) => '${ |
| 64 | .join(' '); |
| 65 | } |
| 66 | |
| 67 | bool? _coerceToBool(dynamic |
| 68 | if (value is bool) return |
| 69 | if (value is num) { |
| 70 | if (value == 1) return |
| 71 | if (value == 0) return |
| 72 | return null; |
| 73 | } |
| 74 | if (value is String) { |
| 75 | final v = value.trim |
| 76 | if (v == 'true' || v == |
| 77 | if (v == 'false' || v == |
| 78 | if (v == '1') return |
| 79 | if (v == '0') return |
| 80 | return null; |
| 81 | } |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | String _formatPayloadValue(dynamic |
| 86 | if (value is String) { |
| 87 | try { |
| 88 | final parsed = DateTime. |
| 89 | return formatDate(parsed); |
| 90 | } catch (_) { |
| 91 | // not a parsable date string; fall through |
| 92 | } |
| 93 | } |
| 94 | return "$value" |
| 95 | } |
| 96 | |
| 97 | /// Opt this device into push alerts for the flight: request notification |
| 98 | /// permission, then register the OneSignal subscription ID with the backend. |
| 99 | Future<void> _setupFlightAlerts |
| 100 | try { |
| 101 | final accepted = await OneSignal |
| 102 | if (!accepted) { |
| 103 | showErrorToast('Enable notifications to get flight alerts.'); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | final playerId = OneSignal. |
| 108 | if (playerId == null || playerId. |
| 109 | showErrorToast('Could not register this device. Please try again.'); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | await alertsService.subscribe(widget.info |
| 114 | showSuccessToast( |
| 115 | description: "You'll be notified of changes to this flight.", |
| 116 | ); |
| 117 | } catch (e) { |
| 118 | showErrorToast(e); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | Future<void> _shareFlightCard |
| 123 | try { |
| 124 | // Capture screenshot |
| 125 | final imageBytes = await _screenshotController. |
| 126 | InheritedTheme.captureAll( |
| 127 | context, |
| 128 | MediaQuery( |
| 129 | data: MediaQuery.of(context) |
| 130 | child: ShareableFlightCard(info: widget. |
| 131 | ), |
| 132 | ), |
| 133 | pixelRatio: 2.0, |
| 134 | delay: const Duration(milliseconds |
| 135 | ); |
| 136 | |
| 137 | if (imageBytes.isEmpty) { |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | // Save to temporary file |
| 142 | final tempDir = await getTemporaryDirectory |
| 143 | final file = File( |
| 144 | '${tempDir.path} |
| 145 | await file.writeAsBytes(imageBytes); |
| 146 | |
| 147 | // Share the file |
| 148 | await Share.shareXFiles( |
| 149 | [XFile(file.path)], |
| 150 | text: 'Check out my flight!', |
| 151 | ); |
| 152 | } catch (e) { |
| 153 | // Handle error silently or show a snackbar |
| 154 | if (mounted) { |
| 155 | ScaffoldMessenger.of(context).showSnackBar |
| 156 | SnackBar( |
| 157 | content: Text('Failed to share flight card: $e |
| 158 | ), |
| 159 | ); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | Widget _buildBanner( |
| 165 | BuildContext context, Color color |
| 166 | [String? subtitle]) { |
| 167 | final theme = Theme. |
| 168 | return Container( |
| 169 | padding: const EdgeInsets. |
| 170 | decoration: BoxDecoration( |
| 171 | borderRadius: BorderRadius.circular( |
| 172 | border: Border.all( |
| 173 | color: theme.dividerColor.withValues(alpha |
| 174 | ), |
| 175 | ), |
| 176 | child: Row( |
| 177 | crossAxisAlignment: CrossAxisAlignment.start, |
| 178 | children: [ |
| 179 | Container( |
| 180 | width: 32, |
| 181 | height: 32, |
| 182 | decoration: BoxDecoration( |
| 183 | color: color.withValues(alpha: |
| 184 | borderRadius: BorderRadius.circular( |
| 185 | ), |
| 186 | child: Icon( |
| 187 | icon, |
| 188 | size: 18, |
| 189 | color: color, |
| 190 | ), |
| 191 | ), |
| 192 | const SizedBox(width: |
| 193 | Expanded( |
| 194 | child: Column( |
| 195 | crossAxisAlignment: CrossAxisAlignment.start, |
| 196 | spacing: subtitle != null ? 4 |
| 197 | children: [ |
| 198 | Text( |
| 199 | title, |
| 200 | style: const TextStyle( |
| 201 | fontWeight: FontWeight.w700, |
| 202 | ), |
| 203 | ), |
| 204 | if (subtitle != null) |
| 205 | Text( |
| 206 | subtitle, |
| 207 | style: TextStyle( |
| 208 | color: theme.textTheme.bodySmall?.color |
| 209 | alpha: |
| 210 | theme.brightness == Brightness.dark |
| 211 | ), |
| 212 | ), |
| 213 | ], |
| 214 | ), |
| 215 | ), |
| 216 | ], |
| 217 | ), |
| 218 | ); |
| 219 | } |
| 220 | |
| 221 | Widget _buildFlightStatusBanner(BuildContext |
| 222 | final fa = widget.info. |
| 223 | if (fa?.cancelled == true) { |
| 224 | return Container( |
| 225 | width: double.infinity, |
| 226 | padding: const EdgeInsets. |
| 227 | decoration: BoxDecoration( |
| 228 | color: Colors.red, |
| 229 | borderRadius: BorderRadius.circular( |
| 230 | ), |
| 231 | child: Column( |
| 232 | crossAxisAlignment: CrossAxisAlignment.start, |
| 233 | children: [ |
| 234 | Text( |
| 235 | 'Flight Cancelled', |
| 236 | style: const TextStyle( |
| 237 | color: Colors.white, |
| 238 | fontSize: 16, |
| 239 | fontWeight: FontWeight.bold, |
| 240 | ), |
| 241 | ), |
| 242 | const SizedBox(height: |
| 243 | Text( |
| 244 | 'Contact your airline', |
| 245 | style: TextStyle( |
| 246 | color: Colors.white.withValues |
| 247 | fontSize: 13, |
| 248 | ), |
| 249 | ), |
| 250 | ], |
| 251 | ), |
| 252 | ); |
| 253 | } |
| 254 | if (fa?.diverted == true) { |
| 255 | return _buildBanner( |
| 256 | context, |
| 257 | Colors.amber, |
| 258 | Icons.warning_amber_rounded, |
| 259 | 'This flight has been diverted', |
| 260 | ); |
| 261 | } |
| 262 | return const SizedBox |
| 263 | } |
| 264 | |
| 265 | @override |
| 266 | Widget build(BuildContext |
| 267 | final arrival = widget.info. |
| 268 | final departure = widget.info. |
| 269 | final codeshares = widget.info. |
| 270 | ?.where((code) => code. |
| 271 | .map((code) => code.trim |
| 272 | .toList(growable: false) |
| 273 | const <String>[] |
| 274 | return Padding( |
| 275 | padding: const EdgeInsets. |
| 276 | 4.0, |
| 277 | ), |
| 278 | child: Column( |
| 279 | crossAxisAlignment: CrossAxisAlignment.start, |
| 280 | spacing: 4, |
| 281 | children: [ |
| 282 | if (DateTime.now() |
| 283 | _buildBanner( |
| 284 | context, |
| 285 | Colors.orange, |
| 286 | Icons.history, |
| 287 | 'Flight data may be inaccurate', |
| 288 | 'This flight is more than 7 days old. Times and status may no longer be updated.', |
| 289 | ), |
| 290 | Row( |
| 291 | spacing: 8, |
| 292 | crossAxisAlignment: CrossAxisAlignment.center, |
| 293 | children: [ |
| 294 | CachedNetworkImage( |
| 295 | imageUrl: |
| 296 | "https://www.flightaware.com/images/airline_logos/180px/${widget.info. |
| 297 | width: 30, |
| 298 | height: 30, |
| 299 | errorWidget: (context, url, error) { |
| 300 | return SizedBox( |
| 301 | height: 0, |
| 302 | width: 0, |
| 303 | ); |
| 304 | }, |
| 305 | ), |
| 306 | Column( |
| 307 | spacing: 2, |
| 308 | crossAxisAlignment: CrossAxisAlignment.start, |
| 309 | children: [ |
| 310 | Row( |
| 311 | children: [ |
| 312 | Text( |
| 313 | "${departure.airport. |
| 314 | style: TextStyle( |
| 315 | fontWeight: FontWeight.bold, |
| 316 | fontSize: 16, |
| 317 | ), |
| 318 | ) |
| 319 | ], |
| 320 | ), |
| 321 | Row( |
| 322 | children: [ |
| 323 | Text( |
| 324 | formatDayAndMonth( |
| 325 | DateTime.parse( |
| 326 | (departure.revisedTime ?? departure.scheduledTime) |
| 327 | .utc), |
| 328 | ), |
| 329 | style: TextStyle( |
| 330 | fontWeight: FontWeight.bold, |
| 331 | color: Theme.of(context) |
| 332 | fontSize: 12, |
| 333 | ), |
| 334 | ), |
| 335 | Text( |
| 336 | " • ", |
| 337 | style: Theme.of(context) |
| 338 | fontSize: 12, |
| 339 | ), |
| 340 | ), |
| 341 | Text( |
| 342 | widget.info.flightNo, |
| 343 | style: TextStyle( |
| 344 | fontWeight: FontWeight.bold, |
| 345 | color: Theme.of(context) |
| 346 | fontSize: 12, |
| 347 | ), |
| 348 | ), |
| 349 | if (widget.info.flightAwareData?.identIata |
| 350 | Text( |
| 351 | " • ", |
| 352 | style: |
| 353 | Theme.of(context).textTheme |
| 354 | fontSize: 12, |
| 355 | ), |
| 356 | ), |
| 357 | Text( |
| 358 | widget.info.flightAwareData?.identIata ?? |
| 359 | style: TextStyle( |
| 360 | fontWeight: FontWeight.bold, |
| 361 | color: |
| 362 | Theme.of(context).textTheme |
| 363 | fontSize: 12, |
| 364 | ), |
| 365 | ), |
| 366 | ] |
| 367 | ], |
| 368 | ), |
| 369 | ], |
| 370 | ), |
| 371 | Spacer(), |
| 372 | Row( |
| 373 | spacing: 4, |
| 374 | children: [ |
| 375 | PopupMenuButton( |
| 376 | icon: Icon(Icons. |
| 377 | color: Colors.white, |
| 378 | itemBuilder: (context) => [ |
| 379 | if (widget.onRefreshTracking != null) |
| 380 | PopupMenuItem( |
| 381 | value: 'refresh_tracking', |
| 382 | child: Row( |
| 383 | children: [ |
| 384 | Icon( |
| 385 | Icons.refresh, |
| 386 | ), |
| 387 | SizedBox(width: 8), |
| 388 | Text('Refresh tracking'), |
| 389 | ], |
| 390 | ), |
| 391 | ), |
| 392 | PopupMenuItem( |
| 393 | value: 'refresh_flight_data', |
| 394 | child: Row( |
| 395 | children: [ |
| 396 | Icon( |
| 397 | Icons.refresh, |
| 398 | ), |
| 399 | SizedBox(width: 8), |
| 400 | Text('Refresh flight data'), |
| 401 | ], |
| 402 | ), |
| 403 | ), |
| 404 | PopupMenuItem( |
| 405 | value: 'send_to_wearable', |
| 406 | child: Row( |
| 407 | children: [ |
| 408 | Icon( |
| 409 | Icons.watch, |
| 410 | ), |
| 411 | SizedBox(width: 8), |
| 412 | Text('Send to wearable'), |
| 413 | ], |
| 414 | ), |
| 415 | ), |
| 416 | PopupMenuItem( |
| 417 | value: 'get_alerts', |
| 418 | child: Row( |
| 419 | children: [ |
| 420 | Icon(Icons.notifications_active), |
| 421 | SizedBox(width: 8), |
| 422 | Text('Get alerts'), |
| 423 | ], |
| 424 | ), |
| 425 | ), |
| 426 | PopupMenuItem( |
| 427 | value: 'booking_details', |
| 428 | child: Row( |
| 429 | children: [ |
| 430 | Icon(Icons.confirmation_number), |
| 431 | SizedBox(width: 8), |
| 432 | Text('Booking details'), |
| 433 | ], |
| 434 | ), |
| 435 | ), |
| 436 | PopupMenuItem( |
| 437 | value: 'share', |
| 438 | child: Row( |
| 439 | children: [ |
| 440 | Icon(Icons.share), |
| 441 | SizedBox(width: 8), |
| 442 | Text('Share'), |
| 443 | ], |
| 444 | ), |
| 445 | ), |
| 446 | ], |
| 447 | onSelected: (value) async { |
| 448 | if (value == "refresh_tracking") { |
| 449 | widget.onRefreshTracking?.call(); |
| 450 | } else if (value == "send_to_wearable") { |
| 451 | final channel = MethodChannel( |
| 452 | final flightNumber = widget.info. |
| 453 | final airline = widget.info. |
| 454 | final flightAwareData = widget.info. |
| 455 | final departureAirport = departure.airport; |
| 456 | final arrivalAirport = widget.info. |
| 457 | final departureDate = DateTime. |
| 458 | (departure.revisedTime ?? departure.scheduledTime) |
| 459 | .utc, |
| 460 | ); |
| 461 | |
| 462 | final airlineIata = airline.iata ?? |
| 463 | final airlineIcao = airline.icao ?? |
| 464 | final flightNumberWithoutIata = |
| 465 | flightNumber.replaceFirst(airlineIata, '') |
| 466 | final flightNumberWithoutIcao = |
| 467 | flightNumber.replaceFirst(airlineIcao, '') |
| 468 | |
| 469 | String? _fallbackIdent( |
| 470 | String? primary, |
| 471 | String carrier, |
| 472 | String strippedNumber, |
| 473 | ) { |
| 474 | if (primary != null && primary. |
| 475 | return primary; |
| 476 | } |
| 477 | if (carrier.isEmpty) return null |
| 478 | final number = strippedNumber.isNotEmpty |
| 479 | ? strippedNumber |
| 480 | : flightNumber; |
| 481 | return "$carrier$ |
| 482 | } |
| 483 | |
| 484 | final identIata = _fallbackIdent( |
| 485 | flightAwareData?.identIata, |
| 486 | airlineIata, |
| 487 | flightNumberWithoutIata, |
| 488 | ); |
| 489 | |
| 490 | final identIcao = _fallbackIdent( |
| 491 | flightAwareData?.identIcao, |
| 492 | airlineIcao, |
| 493 | flightNumberWithoutIcao, |
| 494 | ); |
| 495 | |
| 496 | final departureAirportCode = |
| 497 | departureAirport.iata.isNotEmpty |
| 498 | ? departureAirport.iata |
| 499 | : departureAirport.icao; |
| 500 | final arrivalAirportCode = |
| 501 | arrivalAirport.iata.isNotEmpty |
| 502 | ? arrivalAirport.iata |
| 503 | : arrivalAirport.icao; |
| 504 | final departureCity = |
| 505 | departureAirport.municipalityName.isNotEmpty |
| 506 | ? departureAirport.municipalityName |
| 507 | : departureAirport.name; |
| 508 | final arrivalCity = |
| 509 | arrivalAirport.municipalityName.isNotEmpty |
| 510 | ? arrivalAirport.municipalityName |
| 511 | : arrivalAirport.name; |
| 512 | |
| 513 | final payload = { |
| 514 | "flight": { |
| 515 | "id": widget.info.id, |
| 516 | "flightNo": flightNumber, |
| 517 | "identIata": identIata, |
| 518 | "identIcao": identIcao, |
| 519 | "date": departureDate.toIso8601String(), |
| 520 | "departureAirportIata": departureAirportCode, |
| 521 | "departureCity": departureCity, |
| 522 | "arrivalAirportIata": arrivalAirportCode, |
| 523 | "arrivalCity": arrivalCity, |
| 524 | }, |
| 525 | "airline": { |
| 526 | "name": airline.name, |
| 527 | "iata": airline.iata, |
| 528 | "icao": airline.icao, |
| 529 | "image": airline.image, |
| 530 | }, |
| 531 | }; |
| 532 | |
| 533 | await channel.invokeMethod("registerFlight", |
| 534 | print(payload); |
| 535 | ScaffoldMessenger.of(context).showSnackBar |
| 536 | SnackBar( |
| 537 | content: Text('Flight sent to wearable'), |
| 538 | ), |
| 539 | ); |
| 540 | } |
| 541 | if (value == "refresh_flight_data") { |
| 542 | widget.onRefreshFlightData?.call(); |
| 543 | } |
| 544 | if (value == "share") { |
| 545 | _shareFlightCard(); |
| 546 | } |
| 547 | if (value == "booking_details") { |
| 548 | widget.onBookingDetails?.call(); |
| 549 | } |
| 550 | if (value == "get_alerts") { |
| 551 | await _setupFlightAlerts(); |
| 552 | } |
| 553 | }, |
| 554 | ), |
| 555 | SizedBox( |
| 556 | width: 24, |
| 557 | child: IconButton( |
| 558 | onPressed: widget.onClose, |
| 559 | padding: EdgeInsets.zero, |
| 560 | icon: Icon(Icons. |
| 561 | ), |
| 562 | ), |
| 563 | ], |
| 564 | ) |
| 565 | ], |
| 566 | ), |
| 567 | Divider(), |
| 568 | if ((widget.info.flightAwareData?.cancelled |
| 569 | (widget.info.flightAwareData?.diverted == |
| 570 | _buildFlightStatusBanner(context), |
| 571 | Gap(8), |
| 572 | ], |
| 573 | if (widget.info.flightAwareData?.cancelled |
| 574 | Column( |
| 575 | crossAxisAlignment: CrossAxisAlignment.start, |
| 576 | children: [ |
| 577 | Text( |
| 578 | getTimeMessage( |
| 579 | DateTime.parse( |
| 580 | (departure.revisedTime ?? |
| 581 | departure.predictedTime ?? |
| 582 | departure.scheduledTime) |
| 583 | .utc, |
| 584 | ), |
| 585 | DateTime.parse( |
| 586 | (arrival.revisedTime ?? |
| 587 | arrival.predictedTime ?? |
| 588 | arrival.scheduledTime) |
| 589 | .utc, |
| 590 | ), |
| 591 | ), |
| 592 | style: TextStyle( |
| 593 | fontSize: 18, |
| 594 | fontWeight: FontWeight.bold, |
| 595 | ), |
| 596 | ), |
| 597 | ], |
| 598 | ), |
| 599 | FlightRouteInfo( |
| 600 | arrivalCode: arrival.airport.iata, |
| 601 | arrivalDelay: _calculateDelay(arrival.revisedTime, |
| 602 | arrival.predictedTime ?? arrival.scheduledTime), |
| 603 | arrivalName: arrival.airport.name, |
| 604 | arrivalSubtitle: "", |
| 605 | arrivalTerminal: arrival.terminal, |
| 606 | arrivalTime: DateTime.parse((arrival |
| 607 | arrival.predictedTime ?? |
| 608 | arrival.scheduledTime) |
| 609 | .utc), |
| 610 | arrivalTimezone: arrival.airport.timeZone, |
| 611 | departureCode: departure.airport.iata, |
| 612 | departureDelay: _calculateDelay(departure.revisedTime, |
| 613 | departure.predictedTime ?? departure.scheduledTime), |
| 614 | departureName: departure.airport.name, |
| 615 | departureSubtitle: "", |
| 616 | departureTerminal: departure.terminal, |
| 617 | departureTime: DateTime.parse((departure |
| 618 | departure.predictedTime ?? |
| 619 | departure.scheduledTime) |
| 620 | .utc), |
| 621 | departureTimezone: departure.airport.timeZone, |
| 622 | statusColor: Colors.green, |
| 623 | use24Hrs: MediaQuery.of(context) |
| 624 | arrivalGate: |
| 625 | widget.info.flightAwareData?.gateDestination ?? arrival |
| 626 | departureGate: |
| 627 | widget.info.flightAwareData?.gateOrigin ?? departure |
| 628 | arrivalBaggage: widget.info.flightAwareData?.baggageClaim |
| 629 | arrival.baggageBelt, |
| 630 | distanceKm: widget.info.greatCircleDistance.km != |
| 631 | ? double.tryParse(widget |
| 632 | : null, |
| 633 | flightAwareDataEntity: widget.info.flightAwareData, |
| 634 | ), |
| 635 | Gap(8), |
| 636 | Text( |
| 637 | "Worth Noting", |
| 638 | style: TextStyle( |
| 639 | fontSize: 16, |
| 640 | fontWeight: FontWeight.bold, |
| 641 | ), |
| 642 | ), |
| 643 | Column( |
| 644 | children: [ |
| 645 | _buildTimezonePill( |
| 646 | context: context, |
| 647 | arrival: arrival, |
| 648 | departure: departure, |
| 649 | ), |
| 650 | if (codeshares.isNotEmpty) ...[ |
| 651 | const Gap(8) |
| 652 | _buildCodesharePill(context, codeshares), |
| 653 | ], |
| 654 | ], |
| 655 | ), |
| 656 | // Flight Timetable Section |
| 657 | if (widget.info.flightAwareData != null |
| 658 | _buildFlightTimetable(context), |
| 659 | // Airport Conditions Section |
| 660 | _buildAirportConditionsSection(context), |
| 661 | // Booking Details Section |
| 662 | if (widget.info.bookings != null |
| 663 | widget.info.bookings!.isNotEmpty) ...[ |
| 664 | Gap(8), |
| 665 | Text( |
| 666 | "Booking Details", |
| 667 | style: TextStyle( |
| 668 | fontSize: 16, |
| 669 | fontWeight: FontWeight.bold, |
| 670 | ), |
| 671 | ), |
| 672 | Container( |
| 673 | decoration: BoxDecoration( |
| 674 | border: Border.all( |
| 675 | color: Colors.grey.shade300 |
| 676 | ), |
| 677 | borderRadius: BorderRadius.circular( |
| 678 | ), |
| 679 | child: Padding( |
| 680 | padding: const EdgeInsets. |
| 681 | top: 0, |
| 682 | bottom: 0, |
| 683 | ), |
| 684 | child: Column( |
| 685 | crossAxisAlignment: CrossAxisAlignment.stretch, |
| 686 | spacing: 8, |
| 687 | children: [ |
| 688 | Builder(builder: (context) { |
| 689 | final booking = widget.info. |
| 690 | |
| 691 | // Extract string values from JsonObject |
| 692 | String? _extractString(dynamic |
| 693 | if (jsonObject == null) return |
| 694 | if (jsonObject is String) return |
| 695 | try { |
| 696 | final value = (jsonObject as dynamic |
| 697 | if (value is String) return |
| 698 | return value?.toString() |
| 699 | } catch (e) { |
| 700 | return jsonObject.toString(); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | final bookingCode = _extractString(booking |
| 705 | final seatNumber = _extractString(booking |
| 706 | final seatingClass = booking.seatingClass? |
| 707 | final seatType = booking.seatType? |
| 708 | final reason = booking.reason? |
| 709 | |
| 710 | return Column( |
| 711 | crossAxisAlignment: CrossAxisAlignment.start, |
| 712 | children: [ |
| 713 | if (bookingCode != null && bookingCode. |
| 714 | ListTile( |
| 715 | contentPadding: EdgeInsets.zero, |
| 716 | leading: Icon(Icons. |
| 717 | title: Text( |
| 718 | 'Booking Code: $bookingCode', |
| 719 | style: TextStyle( |
| 720 | fontWeight: FontWeight.w600, |
| 721 | ), |
| 722 | ), |
| 723 | ), |
| 724 | if (seatNumber != null && seatNumber. |
| 725 | ListTile( |
| 726 | contentPadding: EdgeInsets.zero, |
| 727 | leading: Icon(Icons. |
| 728 | title: Text( |
| 729 | 'Seat: $seatNumber${seatType != |
| 730 | style: TextStyle( |
| 731 | fontWeight: FontWeight.w600, |
| 732 | ), |
| 733 | ), |
| 734 | ), |
| 735 | if (seatingClass != null) |
| 736 | ListTile( |
| 737 | contentPadding: EdgeInsets.zero, |
| 738 | leading: Icon(Icons. |
| 739 | title: Text( |
| 740 | 'Class: ${_formatEnumName(seatingClass)} |
| 741 | style: TextStyle( |
| 742 | fontWeight: FontWeight.w600, |
| 743 | ), |
| 744 | ), |
| 745 | ), |
| 746 | if (reason != null) |
| 747 | ListTile( |
| 748 | contentPadding: EdgeInsets.zero, |
| 749 | leading: Icon(Icons. |
| 750 | title: Text( |
| 751 | 'Reason: ${_formatEnumName(reason)} |
| 752 | style: TextStyle( |
| 753 | fontWeight: FontWeight.w600, |
| 754 | ), |
| 755 | ), |
| 756 | ), |
| 757 | ], |
| 758 | ); |
| 759 | }), |
| 760 | ], |
| 761 | ), |
| 762 | ), |
| 763 | ), |
| 764 | ], |
| 765 | Gap(8), |
| 766 | if (widget.info.aircraft?.model |
| 767 | Text( |
| 768 | widget.info.aircraft!.model!, |
| 769 | style: TextStyle( |
| 770 | fontSize: 16, |
| 771 | fontWeight: FontWeight.bold, |
| 772 | ), |
| 773 | ), |
| 774 | if (widget.info.aircraft?.registration |
| 775 | Container( |
| 776 | decoration: BoxDecoration( |
| 777 | border: Border.all( |
| 778 | color: Colors.grey.shade300 |
| 779 | ), |
| 780 | borderRadius: BorderRadius.circular( |
| 781 | 5, |
| 782 | ), |
| 783 | ), |
| 784 | child: Padding( |
| 785 | padding: const EdgeInsets. |
| 786 | 8.0, |
| 787 | ), |
| 788 | child: Column( |
| 789 | crossAxisAlignment: CrossAxisAlignment.stretch, |
| 790 | spacing: 8, |
| 791 | children: [ |
| 792 | if (widget.info.aircraft!.image |
| 793 | ClipRRect( |
| 794 | borderRadius: BorderRadius.circular( |
| 795 | 5, |
| 796 | ), |
| 797 | child: CachedNetworkImage( |
| 798 | imageUrl: widget.info.aircraft!.image |
| 799 | ), |
| 800 | ), |
| 801 | Wrap( |
| 802 | spacing: 10, |
| 803 | alignment: WrapAlignment.spaceBetween, |
| 804 | runSpacing: 10, |
| 805 | children: [ |
| 806 | if (widget.info.aircraft?.age |
| 807 | Column( |
| 808 | crossAxisAlignment: CrossAxisAlignment.start, |
| 809 | children: [ |
| 810 | Text( |
| 811 | "Age", |
| 812 | style: TextStyle( |
| 813 | fontWeight: FontWeight.bold, |
| 814 | color: Colors |
| 815 | .grey[700], // Adjust color as needed |
| 816 | ), |
| 817 | ), |
| 818 | Text( |
| 819 | formatAge( |
| 820 | double.parse( |
| 821 | widget.info.aircraft!.age!, |
| 822 | ), |
| 823 | ), |
| 824 | style: TextStyle( |
| 825 | fontWeight: FontWeight.normal, |
| 826 | color: Colors.black, |
| 827 | ), |
| 828 | ), |
| 829 | ], |
| 830 | ), |
| 831 | if (widget.info.aircraft?.deliveryDate |
| 832 | Column( |
| 833 | crossAxisAlignment: CrossAxisAlignment.end, |
| 834 | children: [ |
| 835 | Text( |
| 836 | "Delivery Date", |
| 837 | style: TextStyle( |
| 838 | fontWeight: FontWeight.bold, |
| 839 | color: Colors |
| 840 | .grey[700], // Adjust color as needed |
| 841 | ), |
| 842 | ), |
| 843 | Text( |
| 844 | formatDate(DateTime.parse |
| 845 | widget.info.aircraft!.deliveryDate!)) |
| 846 | style: TextStyle( |
| 847 | fontWeight: FontWeight.normal, |
| 848 | color: Colors.black, |
| 849 | ), |
| 850 | ), |
| 851 | ], |
| 852 | ), |
| 853 | if (widget.info.aircraft?.registration |
| 854 | Column( |
| 855 | crossAxisAlignment: CrossAxisAlignment.start, |
| 856 | children: [ |
| 857 | Text( |
| 858 | "Registration", |
| 859 | style: TextStyle( |
| 860 | fontWeight: FontWeight.bold, |
| 861 | color: Colors |
| 862 | .grey[700], // Adjust color as needed |
| 863 | ), |
| 864 | ), |
| 865 | Text( |
| 866 | widget.info.aircraft!.registration!, |
| 867 | style: TextStyle( |
| 868 | fontWeight: FontWeight.normal, |
| 869 | color: Colors.black, |
| 870 | ), |
| 871 | ), |
| 872 | const SizedBox(height: |
| 873 | Builder(builder: (context) { |
| 874 | final payload = |
| 875 | (widget.info.aircraft?.payload)?. |
| 876 | final entries = payload == null |
| 877 | ? const <MapEntry |
| 878 | : payload.entries |
| 879 | .where((e) => |
| 880 | e.value is String || |
| 881 | e.value is num || |
| 882 | e.value is bool) |
| 883 | .where((e) => |
| 884 | e.key != 'id' && |
| 885 | e.key != 'numRegistrations') |
| 886 | .toList(); |
| 887 | if (entries.isEmpty) { |
| 888 | return const SizedBox |
| 889 | } |
| 890 | return Column( |
| 891 | crossAxisAlignment: CrossAxisAlignment.start, |
| 892 | children: [ |
| 893 | TextButton( |
| 894 | onPressed: () { |
| 895 | setState(() { |
| 896 | _showAircraftPayload = |
| 897 | !_showAircraftPayload; |
| 898 | }); |
| 899 | }, |
| 900 | style: TextButton.styleFrom( |
| 901 | padding: EdgeInsets.zero, |
| 902 | minimumSize: const Size( |
| 903 | tapTargetSize: |
| 904 | MaterialTapTargetSize.shrinkWrap, |
| 905 | ), |
| 906 | child: Row( |
| 907 | mainAxisSize: MainAxisSize.min, |
| 908 | children: [ |
| 909 | Text( |
| 910 | _showAircraftPayload |
| 911 | ? "Hide more info" |
| 912 | : "Show more info", |
| 913 | style: TextStyle( |
| 914 | fontWeight: FontWeight.w600, |
| 915 | ), |
| 916 | ), |
| 917 | const SizedBox(width: |
| 918 | Icon( |
| 919 | _showAircraftPayload |
| 920 | ? Icons.expand_less |
| 921 | : Icons.expand_more, |
| 922 | size: 18), |
| 923 | ], |
| 924 | ), |
| 925 | ), |
| 926 | if (_showAircraftPayload) |
| 927 | Padding( |
| 928 | padding: |
| 929 | const EdgeInsets.only |
| 930 | child: Column( |
| 931 | crossAxisAlignment: |
| 932 | CrossAxisAlignment.start, |
| 933 | children: entries.map((e) { |
| 934 | final coerced = |
| 935 | _coerceToBool(e.value); |
| 936 | if (coerced != null) { |
| 937 | final boolColor = coerced |
| 938 | ? Colors.green |
| 939 | : Colors.red; |
| 940 | final label = |
| 941 | coerced ? 'Yes' : 'No'; |
| 942 | return Padding( |
| 943 | padding: |
| 944 | const EdgeInsets.symmetric |
| 945 | vertical: 1.0), |
| 946 | child: Row( |
| 947 | mainAxisAlignment: |
| 948 | MainAxisAlignment |
| 949 | .spaceBetween, |
| 950 | children: [ |
| 951 | Expanded( |
| 952 | child: Text( |
| 953 | _formatKey(e.key), |
| 954 | style: TextStyle( |
| 955 | color: |
| 956 | Colors.grey[700], |
| 957 | fontWeight: |
| 958 | FontWeight.w600, |
| 959 | ), |
| 960 | ), |
| 961 | ), |
| 962 | const SizedBox(width: |
| 963 | Row( |
| 964 | mainAxisSize: |
| 965 | MainAxisSize.min, |
| 966 | children: [ |
| 967 | Container( |
| 968 | width: 10, |
| 969 | height: 10, |
| 970 | decoration: |
| 971 | BoxDecoration( |
| 972 | color: boolColor, |
| 973 | shape: |
| 974 | BoxShape.circle, |
| 975 | ), |
| 976 | ), |
| 977 | const SizedBox( |
| 978 | width: 4), |
| 979 | Text( |
| 980 | label, |
| 981 | style: TextStyle( |
| 982 | color: boolColor, |
| 983 | fontSize: 12, |
| 984 | fontWeight: |
| 985 | FontWeight.w600, |
| 986 | ), |
| 987 | ), |
| 988 | ], |
| 989 | ), |
| 990 | ], |
| 991 | ), |
| 992 | ); |
| 993 | } |
| 994 | return Padding( |
| 995 | padding: |
| 996 | const EdgeInsets.symmetric |
| 997 | vertical: 1.0), |
| 998 | child: Row( |
| 999 | mainAxisAlignment: |
| 1000 | MainAxisAlignment |
| 1001 | .spaceBetween, |
| 1002 | children: [ |
| 1003 | Expanded( |
| 1004 | child: Text( |
| 1005 | _formatKey(e.key), |
| 1006 | style: TextStyle( |
| 1007 | color: Colors.grey[700] |
| 1008 | fontWeight: |
| 1009 | FontWeight.w600, |
| 1010 | ), |
| 1011 | ), |
| 1012 | ), |
| 1013 | const SizedBox(width: |
| 1014 | Flexible( |
| 1015 | child: Text( |
| 1016 | _formatPayloadValue( |
| 1017 | e.value), |
| 1018 | textAlign: |
| 1019 | TextAlign.right, |
| 1020 | overflow: |
| 1021 | TextOverflow.ellipsis, |
| 1022 | ), |
| 1023 | ), |
| 1024 | ], |
| 1025 | ), |
| 1026 | ); |
| 1027 | }).toList(), |
| 1028 | ), |
| 1029 | ), |
| 1030 | ], |
| 1031 | ); |
| 1032 | }), |
| 1033 | ], |
| 1034 | ), |
| 1035 | ], |
| 1036 | ) |
| 1037 | ], |
| 1038 | ), |
| 1039 | ), |
| 1040 | ), |
| 1041 | if (widget.info.aircraft?.registrations |
| 1042 | widget.info.aircraft!.registrations!. |
| 1043 | Gap(8), |
| 1044 | _buildRegistrationHistoryCard(context), |
| 1045 | ], |
| 1046 | // Jet2 Holiday Meme |
| 1047 | if (widget.info.airline.icao == |
| 1048 | widget.info.airline.iata == 'LS' |
| 1049 | const Gap(16) |
| 1050 | _buildJet2Meme(context), |
| 1051 | ], |
| 1052 | ], |
| 1053 | ), |
| 1054 | ); |
| 1055 | } |
| 1056 | |
| 1057 | Widget _buildRegistrationHistoryCard(BuildContext |
| 1058 | final theme = Theme. |
| 1059 | final registrations = widget.info. |
| 1060 | registrations.sort((a, b) { |
| 1061 | final ad = a.registrationDate; |
| 1062 | final bd = b.registrationDate; |
| 1063 | if (ad == null && bd == |
| 1064 | if (ad == null) return |
| 1065 | if (bd == null) return |
| 1066 | return DateTime.parse |
| 1067 | }); |
| 1068 | |
| 1069 | return Column( |
| 1070 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1071 | children: [ |
| 1072 | Text( |
| 1073 | "Registration History", |
| 1074 | style: TextStyle( |
| 1075 | fontSize: 16, |
| 1076 | fontWeight: FontWeight.bold, |
| 1077 | ), |
| 1078 | ), |
| 1079 | const Gap(6) |
| 1080 | Container( |
| 1081 | padding: const EdgeInsets. |
| 1082 | decoration: BoxDecoration( |
| 1083 | borderRadius: BorderRadius.circular( |
| 1084 | border: Border.all( |
| 1085 | color: theme.dividerColor.withValues(alpha |
| 1086 | ), |
| 1087 | ), |
| 1088 | child: Column( |
| 1089 | crossAxisAlignment: CrossAxisAlignment.stretch, |
| 1090 | children: [ |
| 1091 | for (int i = 0 |
| 1092 | if (i > 0) |
| 1093 | Divider( |
| 1094 | height: 16, |
| 1095 | color: theme.dividerColor.withValues(alpha |
| 1096 | ), |
| 1097 | _buildRegistrationRow(context, registrations[i]), |
| 1098 | ], |
| 1099 | ], |
| 1100 | ), |
| 1101 | ), |
| 1102 | ], |
| 1103 | ); |
| 1104 | } |
| 1105 | |
| 1106 | Widget _buildRegistrationRow( |
| 1107 | BuildContext context, AircraftRegistrationEntity reg) { |
| 1108 | final theme = Theme. |
| 1109 | final statusColor = reg.active ? |
| 1110 | final statusLabel = reg.active ? |
| 1111 | String? dateLabel; |
| 1112 | if (reg.registrationDate != null) { |
| 1113 | try { |
| 1114 | dateLabel = formatDate(DateTime. |
| 1115 | } catch (_) {} |
| 1116 | } |
| 1117 | return Row( |
| 1118 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1119 | children: [ |
| 1120 | Container( |
| 1121 | margin: const EdgeInsets. |
| 1122 | width: 8, |
| 1123 | height: 8, |
| 1124 | decoration: BoxDecoration( |
| 1125 | color: statusColor, |
| 1126 | shape: BoxShape.circle, |
| 1127 | ), |
| 1128 | ), |
| 1129 | const SizedBox(width: |
| 1130 | Expanded( |
| 1131 | child: Column( |
| 1132 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1133 | children: [ |
| 1134 | Row( |
| 1135 | children: [ |
| 1136 | Text( |
| 1137 | reg.reg, |
| 1138 | style: const TextStyle( |
| 1139 | fontWeight: FontWeight.w700, |
| 1140 | fontSize: 14, |
| 1141 | ), |
| 1142 | ), |
| 1143 | const SizedBox(width: |
| 1144 | Container( |
| 1145 | padding: |
| 1146 | const EdgeInsets.symmetric |
| 1147 | decoration: BoxDecoration( |
| 1148 | color: statusColor.withValues(alpha: |
| 1149 | borderRadius: BorderRadius.circular( |
| 1150 | ), |
| 1151 | child: Text( |
| 1152 | statusLabel, |
| 1153 | style: TextStyle( |
| 1154 | color: statusColor, |
| 1155 | fontSize: 10, |
| 1156 | fontWeight: FontWeight.w700, |
| 1157 | ), |
| 1158 | ), |
| 1159 | ), |
| 1160 | ], |
| 1161 | ), |
| 1162 | if (reg.airlineName != null && |
| 1163 | Padding( |
| 1164 | padding: const EdgeInsets. |
| 1165 | child: Text( |
| 1166 | reg.airlineName!, |
| 1167 | style: TextStyle( |
| 1168 | fontSize: 12, |
| 1169 | color: theme.textTheme.bodySmall?.color |
| 1170 | ), |
| 1171 | ), |
| 1172 | ), |
| 1173 | if (dateLabel != null) |
| 1174 | Padding( |
| 1175 | padding: const EdgeInsets. |
| 1176 | child: Text( |
| 1177 | 'Registered on: $dateLabel', |
| 1178 | style: TextStyle( |
| 1179 | fontSize: 11, |
| 1180 | color: theme.textTheme.bodySmall?.color |
| 1181 | ?.withValues(alpha: 0.7 |
| 1182 | ), |
| 1183 | ), |
| 1184 | ), |
| 1185 | if (reg.hexIcao != null && |
| 1186 | Padding( |
| 1187 | padding: const EdgeInsets. |
| 1188 | child: Text( |
| 1189 | 'ICAO Hex: ${reg.hexIcao!} |
| 1190 | style: TextStyle( |
| 1191 | fontSize: 11, |
| 1192 | fontFamily: 'monospace', |
| 1193 | color: theme.textTheme.bodySmall?.color |
| 1194 | ?.withValues(alpha: 0.7 |
| 1195 | ), |
| 1196 | ), |
| 1197 | ), |
| 1198 | ], |
| 1199 | ), |
| 1200 | ), |
| 1201 | ], |
| 1202 | ); |
| 1203 | } |
| 1204 | |
| 1205 | Widget _buildJet2Meme(BuildContext |
| 1206 | final isDark = Theme. |
| 1207 | |
| 1208 | return Padding( |
| 1209 | padding: const EdgeInsets. |
| 1210 | child: Center( |
| 1211 | child: Text( |
| 1212 | 'Nothing beats a Jet2 holiday', |
| 1213 | textAlign: TextAlign.center, |
| 1214 | style: TextStyle( |
| 1215 | fontSize: 10, |
| 1216 | fontWeight: FontWeight.w400, |
| 1217 | letterSpacing: 0.5, |
| 1218 | color: isDark ? Colors.grey[ |
| 1219 | ), |
| 1220 | ), |
| 1221 | ), |
| 1222 | ); |
| 1223 | } |
| 1224 | |
| 1225 | Widget _buildFlightTimetable(BuildContext |
| 1226 | final fa = widget.info. |
| 1227 | final departure = widget.info. |
| 1228 | final arrival = widget.info. |
| 1229 | final theme = Theme. |
| 1230 | final use24Hrs = MediaQuery. |
| 1231 | |
| 1232 | final depTz = _sanitizeTimezone(departure |
| 1233 | final arrTz = _sanitizeTimezone(arrival |
| 1234 | |
| 1235 | // Check if any timetable data exists |
| 1236 | final hasAnyData = fa.scheduledOut != |
| 1237 | fa.estimatedOut != null || |
| 1238 | fa.actualOut != null || |
| 1239 | fa.scheduledOff != null || |
| 1240 | fa.estimatedOff != null || |
| 1241 | fa.actualOff != null || |
| 1242 | fa.scheduledOn != null || |
| 1243 | fa.estimatedOn != null || |
| 1244 | fa.actualOn != null || |
| 1245 | fa.scheduledIn != null || |
| 1246 | fa.estimatedIn != null || |
| 1247 | fa.actualIn != null; |
| 1248 | |
| 1249 | if (!hasAnyData) return const |
| 1250 | |
| 1251 | try { |
| 1252 | tz.initializeTimeZones(); |
| 1253 | } catch (_) {} |
| 1254 | |
| 1255 | String formatTimeInTz(DateTime |
| 1256 | final location = tz.getLocation |
| 1257 | final tzDt = tz.TZDateTime |
| 1258 | if (use24Hrs) { |
| 1259 | return '${tzDt. |
| 1260 | } |
| 1261 | final hour = tzDt.hour % |
| 1262 | final amPm = tzDt.hour >= |
| 1263 | return '$hour: |
| 1264 | } |
| 1265 | |
| 1266 | String formatDateTimeInTz(DateTime |
| 1267 | final location = tz.getLocation |
| 1268 | final tzDt = tz.TZDateTime |
| 1269 | return '${MONTHS[ |
| 1270 | } |
| 1271 | |
| 1272 | String formatDuration(int |
| 1273 | final absMins = mins.abs |
| 1274 | if (absMins < 60) return |
| 1275 | final hours = absMins ~/ |
| 1276 | final remainder = absMins % 60 |
| 1277 | if (remainder == 0) return |
| 1278 | return '${hours} |
| 1279 | } |
| 1280 | |
| 1281 | /// Returns (label, color) for the status indicator comparing scheduled vs actual/estimated |
| 1282 | (String, Color) getTimeDelta |
| 1283 | if (actual == null) return |
| 1284 | final diff = actual.difference |
| 1285 | final mins = diff.inMinutes; |
| 1286 | if (mins.abs() < |
| 1287 | if (mins < 0) return |
| 1288 | if (mins <= 15) return |
| 1289 | return ('${formatDuration( |
| 1290 | } |
| 1291 | |
| 1292 | Widget buildPhaseRow({ |
| 1293 | required String phase, |
| 1294 | required IconData icon, |
| 1295 | required String timezone, |
| 1296 | required DateTime? scheduled, |
| 1297 | required DateTime? estimated, |
| 1298 | required DateTime? actual, |
| 1299 | }) { |
| 1300 | if (scheduled == null && estimated == |
| 1301 | return const SizedBox |
| 1302 | } |
| 1303 | |
| 1304 | // Determine the best "resolved" time and its status |
| 1305 | final resolvedTime = actual ?? estimated; |
| 1306 | final (deltaLabel, deltaColor) = scheduled != |
| 1307 | ? getTimeDelta(scheduled, resolvedTime) |
| 1308 | : ('', Colors. |
| 1309 | |
| 1310 | return Padding( |
| 1311 | padding: const EdgeInsets. |
| 1312 | child: Column( |
| 1313 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1314 | children: [ |
| 1315 | Row( |
| 1316 | children: [ |
| 1317 | Icon(icon, size: 16 |
| 1318 | const SizedBox(width: |
| 1319 | Text( |
| 1320 | phase, |
| 1321 | style: const TextStyle( |
| 1322 | fontWeight: FontWeight.w700, |
| 1323 | fontSize: 13, |
| 1324 | ), |
| 1325 | ), |
| 1326 | if (deltaLabel.isNotEmpty) ...[ |
| 1327 | const Spacer(), |
| 1328 | Container( |
| 1329 | padding: |
| 1330 | const EdgeInsets.symmetric |
| 1331 | decoration: BoxDecoration( |
| 1332 | color: deltaColor.withValues(alpha: |
| 1333 | borderRadius: BorderRadius.circular( |
| 1334 | ), |
| 1335 | child: Text( |
| 1336 | deltaLabel, |
| 1337 | style: TextStyle( |
| 1338 | color: deltaColor, |
| 1339 | fontSize: 11, |
| 1340 | fontWeight: FontWeight.w700, |
| 1341 | ), |
| 1342 | ), |
| 1343 | ), |
| 1344 | ], |
| 1345 | ], |
| 1346 | ), |
| 1347 | const SizedBox(height: |
| 1348 | Padding( |
| 1349 | padding: const EdgeInsets. |
| 1350 | child: Table( |
| 1351 | columnWidths: const { |
| 1352 | 0: FlexColumnWidth(1) |
| 1353 | 1: FlexColumnWidth(2) |
| 1354 | }, |
| 1355 | children: [ |
| 1356 | if (scheduled != null) |
| 1357 | _buildTimeRow( |
| 1358 | 'Scheduled', |
| 1359 | formatDateTimeInTz(scheduled, timezone), |
| 1360 | Colors.grey.shade600, |
| 1361 | theme), |
| 1362 | if (estimated != null) |
| 1363 | _buildTimeRow( |
| 1364 | 'Estimated', |
| 1365 | formatDateTimeInTz(estimated, timezone), |
| 1366 | actual == null ? deltaColor : Colors |
| 1367 | theme, |
| 1368 | ), |
| 1369 | if (actual != null) |
| 1370 | _buildTimeRow( |
| 1371 | 'Actual', |
| 1372 | formatDateTimeInTz(actual, timezone), |
| 1373 | deltaColor, |
| 1374 | theme, |
| 1375 | bold: true, |
| 1376 | ), |
| 1377 | ], |
| 1378 | ), |
| 1379 | ), |
| 1380 | ], |
| 1381 | ), |
| 1382 | ); |
| 1383 | } |
| 1384 | |
| 1385 | return Column( |
| 1386 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1387 | children: [ |
| 1388 | const Gap(8) |
| 1389 | Text( |
| 1390 | 'Flight Timetable', |
| 1391 | style: TextStyle( |
| 1392 | fontSize: 16, |
| 1393 | fontWeight: FontWeight.bold, |
| 1394 | ), |
| 1395 | ), |
| 1396 | Gap(4), |
| 1397 | Container( |
| 1398 | padding: const EdgeInsets. |
| 1399 | decoration: BoxDecoration( |
| 1400 | borderRadius: BorderRadius.circular( |
| 1401 | border: Border.all( |
| 1402 | color: theme.dividerColor.withValues(alpha |
| 1403 | ), |
| 1404 | ), |
| 1405 | child: Column( |
| 1406 | children: [ |
| 1407 | buildPhaseRow( |
| 1408 | phase: 'Gate Departure', |
| 1409 | icon: Icons.door_sliding_outlined, |
| 1410 | timezone: depTz, |
| 1411 | scheduled: fa.scheduledOut, |
| 1412 | estimated: fa.estimatedOut, |
| 1413 | actual: fa.actualOut, |
| 1414 | ), |
| 1415 | buildPhaseRow( |
| 1416 | phase: 'Takeoff', |
| 1417 | icon: Icons.flight_takeoff, |
| 1418 | timezone: depTz, |
| 1419 | scheduled: fa.scheduledOff, |
| 1420 | estimated: fa.estimatedOff, |
| 1421 | actual: fa.actualOff, |
| 1422 | ), |
| 1423 | buildPhaseRow( |
| 1424 | phase: 'Landing', |
| 1425 | icon: Icons.flight_land, |
| 1426 | timezone: arrTz, |
| 1427 | scheduled: fa.scheduledOn, |
| 1428 | estimated: fa.estimatedOn, |
| 1429 | actual: fa.actualOn, |
| 1430 | ), |
| 1431 | buildPhaseRow( |
| 1432 | phase: 'Gate Arrival', |
| 1433 | icon: Icons.door_front_door_outlined, |
| 1434 | timezone: arrTz, |
| 1435 | scheduled: fa.scheduledIn, |
| 1436 | estimated: fa.estimatedIn, |
| 1437 | actual: fa.actualIn, |
| 1438 | ), |
| 1439 | ], |
| 1440 | ), |
| 1441 | ), |
| 1442 | ], |
| 1443 | ); |
| 1444 | } |
| 1445 | |
| 1446 | Widget _buildAirportConditionsSection(BuildContext |
| 1447 | final departure = widget.info. |
| 1448 | final arrival = widget.info. |
| 1449 | final depConditions = departure.airport. |
| 1450 | final arrConditions = arrival.airport. |
| 1451 | |
| 1452 | final depHas = _hasConditions(depConditions) |
| 1453 | final arrHas = _hasConditions(arrConditions) |
| 1454 | if (!depHas && !arrHas) return |
| 1455 | |
| 1456 | return Column( |
| 1457 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1458 | children: [ |
| 1459 | const Gap(8) |
| 1460 | const Text( |
| 1461 | 'Airport Conditions', |
| 1462 | style: TextStyle(fontSize: 16 |
| 1463 | ), |
| 1464 | const Gap(4) |
| 1465 | if (depHas) |
| 1466 | _buildAirportConditionsCard( |
| 1467 | context, |
| 1468 | label: 'Departure — ${_airportCode(departure |
| 1469 | conditions: depConditions!, |
| 1470 | ), |
| 1471 | if (depHas && arrHas) const Gap |
| 1472 | if (arrHas) |
| 1473 | _buildAirportConditionsCard( |
| 1474 | context, |
| 1475 | label: 'Arrival — ${_airportCode(arrival |
| 1476 | conditions: arrConditions!, |
| 1477 | ), |
| 1478 | ], |
| 1479 | ); |
| 1480 | } |
| 1481 | |
| 1482 | bool _hasConditions(dynamic |
| 1483 | if (conditions == null) return |
| 1484 | return conditions.delays != null |
| 1485 | conditions.forecast != null || |
| 1486 | conditions.observation != null; |
| 1487 | } |
| 1488 | |
| 1489 | Widget _buildAirportConditionsCard( |
| 1490 | BuildContext context, { |
| 1491 | required String label, |
| 1492 | required AirportConditionsEntity conditions, |
| 1493 | }) { |
| 1494 | final theme = Theme. |
| 1495 | final delays = conditions.delays; |
| 1496 | final observation = conditions.observation; |
| 1497 | final forecast = conditions.forecast; |
| 1498 | |
| 1499 | return Container( |
| 1500 | padding: const EdgeInsets. |
| 1501 | decoration: BoxDecoration( |
| 1502 | borderRadius: BorderRadius.circular( |
| 1503 | border: Border.all(color |
| 1504 | ), |
| 1505 | child: Column( |
| 1506 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1507 | children: [ |
| 1508 | Text( |
| 1509 | label, |
| 1510 | style: const TextStyle(fontWeight |
| 1511 | ), |
| 1512 | if (delays != null) ...[ |
| 1513 | const Gap(8) |
| 1514 | _buildDelayRow(context, delays), |
| 1515 | ], |
| 1516 | if (observation != null) ...[ |
| 1517 | const Gap(8) |
| 1518 | _buildObservationRow(context, observation), |
| 1519 | ], |
| 1520 | if (forecast != null) ...[ |
| 1521 | const Gap(8) |
| 1522 | _buildForecastRow(context, forecast), |
| 1523 | ], |
| 1524 | ], |
| 1525 | ), |
| 1526 | ); |
| 1527 | } |
| 1528 | |
| 1529 | Color _delayColor(String |
| 1530 | switch (wireColor) { |
| 1531 | case 'red': |
| 1532 | return Colors.red; |
| 1533 | case 'yellow': |
| 1534 | return Colors.orange; |
| 1535 | case 'green': |
| 1536 | return Colors.green; |
| 1537 | default: |
| 1538 | return Colors.grey; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | String _formatSecondsAsDuration(int |
| 1543 | final mins = (seconds / 60 |
| 1544 | if (mins < 60) return |
| 1545 | final hours = mins ~/ |
| 1546 | final remainder = mins % 60 |
| 1547 | if (remainder == 0) return |
| 1548 | return '${hours} |
| 1549 | } |
| 1550 | |
| 1551 | Widget _buildDelayRow(BuildContext |
| 1552 | final theme = Theme. |
| 1553 | final color = _delayColor(delays |
| 1554 | final delaySecs = (int. |
| 1555 | final duration = _formatSecondsAsDuration(delaySecs) |
| 1556 | final category = (delays.category as |
| 1557 | final reasons = (delays.reasons as |
| 1558 | ?.map((r) => r. |
| 1559 | .where((s) => s.isNotEmpty) |
| 1560 | .toList() ?? |
| 1561 | const <String>[] |
| 1562 | |
| 1563 | return Row( |
| 1564 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1565 | children: [ |
| 1566 | Container( |
| 1567 | width: 32, |
| 1568 | height: 32, |
| 1569 | decoration: BoxDecoration( |
| 1570 | color: color.withValues(alpha: |
| 1571 | borderRadius: BorderRadius.circular( |
| 1572 | ), |
| 1573 | child: Icon(Icons. |
| 1574 | ), |
| 1575 | const SizedBox(width: |
| 1576 | Expanded( |
| 1577 | child: Column( |
| 1578 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1579 | children: [ |
| 1580 | Row( |
| 1581 | children: [ |
| 1582 | const Text( |
| 1583 | 'Delay', |
| 1584 | style: TextStyle(fontWeight: FontWeight |
| 1585 | ), |
| 1586 | const Spacer(), |
| 1587 | Container( |
| 1588 | padding: |
| 1589 | const EdgeInsets.symmetric |
| 1590 | decoration: BoxDecoration( |
| 1591 | color: color.withValues(alpha: |
| 1592 | borderRadius: BorderRadius.circular( |
| 1593 | ), |
| 1594 | child: Text( |
| 1595 | duration, |
| 1596 | style: TextStyle( |
| 1597 | color: color, |
| 1598 | fontSize: 11, |
| 1599 | fontWeight: FontWeight.w700, |
| 1600 | ), |
| 1601 | ), |
| 1602 | ), |
| 1603 | ], |
| 1604 | ), |
| 1605 | const SizedBox(height: |
| 1606 | Text( |
| 1607 | 'Cause: ${_formatEnumName(category)} |
| 1608 | style: TextStyle( |
| 1609 | fontSize: 12, |
| 1610 | color: |
| 1611 | theme.textTheme.bodySmall?.color?. |
| 1612 | ), |
| 1613 | ), |
| 1614 | if (reasons.isNotEmpty) |
| 1615 | Padding( |
| 1616 | padding: const EdgeInsets. |
| 1617 | child: Text( |
| 1618 | reasons.join(' • '), |
| 1619 | style: TextStyle( |
| 1620 | fontSize: 11, |
| 1621 | color: theme.textTheme.bodySmall?.color |
| 1622 | ?.withValues(alpha: 0.7 |
| 1623 | ), |
| 1624 | ), |
| 1625 | ), |
| 1626 | ], |
| 1627 | ), |
| 1628 | ), |
| 1629 | ], |
| 1630 | ); |
| 1631 | } |
| 1632 | |
| 1633 | Widget _buildObservationRow(BuildContext |
| 1634 | final theme = Theme. |
| 1635 | final tempAir = int. |
| 1636 | final tempPerceived = int. |
| 1637 | final windFriendly = observation.windFriendly as |
| 1638 | final cloudFriendly = observation.cloudFriendly? |
| 1639 | final conditions = observation.conditions? |
| 1640 | final visibility = int. |
| 1641 | final visibilityUnits = observation.visibilityUnits? |
| 1642 | |
| 1643 | final parts = <String |
| 1644 | if (tempAir != null) { |
| 1645 | parts.add(tempPerceived != null |
| 1646 | ? '$tempAir°C (feels $ |
| 1647 | : '$tempAir°C') |
| 1648 | } |
| 1649 | if (windFriendly != null && windFriendly. |
| 1650 | parts.add(windFriendly); |
| 1651 | if (cloudFriendly != null && cloudFriendly. |
| 1652 | parts.add(cloudFriendly); |
| 1653 | if (conditions != null && conditions. |
| 1654 | if (visibility != null) { |
| 1655 | final unit = (visibilityUnits == null |
| 1656 | ? '' |
| 1657 | : ' $visibilityUnits'; |
| 1658 | parts.add('Visibility $visibility |
| 1659 | } |
| 1660 | |
| 1661 | if (parts.isEmpty) return const |
| 1662 | |
| 1663 | return Row( |
| 1664 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1665 | children: [ |
| 1666 | Container( |
| 1667 | width: 32, |
| 1668 | height: 32, |
| 1669 | decoration: BoxDecoration( |
| 1670 | color: theme.colorScheme.primary.withValues |
| 1671 | borderRadius: BorderRadius.circular( |
| 1672 | ), |
| 1673 | child: Icon( |
| 1674 | Symbols.partly_cloudy_day, |
| 1675 | size: 18, |
| 1676 | color: theme.colorScheme.primary, |
| 1677 | ), |
| 1678 | ), |
| 1679 | const SizedBox(width: |
| 1680 | Expanded( |
| 1681 | child: Column( |
| 1682 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1683 | children: [ |
| 1684 | const Text( |
| 1685 | 'Current weather', |
| 1686 | style: TextStyle(fontWeight: FontWeight |
| 1687 | ), |
| 1688 | const SizedBox(height: |
| 1689 | Text( |
| 1690 | parts.join(' • '), |
| 1691 | style: TextStyle( |
| 1692 | fontSize: 12, |
| 1693 | color: |
| 1694 | theme.textTheme.bodySmall?.color?. |
| 1695 | ), |
| 1696 | ), |
| 1697 | ], |
| 1698 | ), |
| 1699 | ), |
| 1700 | ], |
| 1701 | ); |
| 1702 | } |
| 1703 | |
| 1704 | Widget _buildForecastRow(BuildContext |
| 1705 | final theme = Theme. |
| 1706 | final raw = (forecast.rawForecast as |
| 1707 | ?.map((e) => e. |
| 1708 | .where((s) => s.isNotEmpty) |
| 1709 | .toList(); |
| 1710 | final headline = (raw != null |
| 1711 | |
| 1712 | if (headline == null) return |
| 1713 | |
| 1714 | return Row( |
| 1715 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1716 | children: [ |
| 1717 | Container( |
| 1718 | width: 32, |
| 1719 | height: 32, |
| 1720 | decoration: BoxDecoration( |
| 1721 | color: theme.colorScheme.secondary.withValues |
| 1722 | borderRadius: BorderRadius.circular( |
| 1723 | ), |
| 1724 | child: Icon( |
| 1725 | Symbols.wb_twilight, |
| 1726 | size: 18, |
| 1727 | color: theme.colorScheme.secondary, |
| 1728 | ), |
| 1729 | ), |
| 1730 | const SizedBox(width: |
| 1731 | Expanded( |
| 1732 | child: Column( |
| 1733 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1734 | children: [ |
| 1735 | const Text( |
| 1736 | 'Forecast (TAF)', |
| 1737 | style: TextStyle(fontWeight: FontWeight |
| 1738 | ), |
| 1739 | const SizedBox(height: |
| 1740 | Text( |
| 1741 | headline, |
| 1742 | style: TextStyle( |
| 1743 | fontSize: 11, |
| 1744 | fontFamily: 'monospace', |
| 1745 | color: |
| 1746 | theme.textTheme.bodySmall?.color?. |
| 1747 | ), |
| 1748 | ), |
| 1749 | ], |
| 1750 | ), |
| 1751 | ), |
| 1752 | ], |
| 1753 | ); |
| 1754 | } |
| 1755 | |
| 1756 | TableRow _buildTimeRow( |
| 1757 | String label, String time |
| 1758 | {bool bold = false}) { |
| 1759 | return TableRow( |
| 1760 | children: [ |
| 1761 | Padding( |
| 1762 | padding: const EdgeInsets. |
| 1763 | child: Text( |
| 1764 | label, |
| 1765 | style: TextStyle( |
| 1766 | fontSize: 12, |
| 1767 | color: theme.textTheme.bodySmall?.color |
| 1768 | ), |
| 1769 | ), |
| 1770 | ), |
| 1771 | Padding( |
| 1772 | padding: const EdgeInsets. |
| 1773 | child: Text( |
| 1774 | time, |
| 1775 | style: TextStyle( |
| 1776 | fontSize: 12, |
| 1777 | fontWeight: bold ? FontWeight.w700 |
| 1778 | color: color, |
| 1779 | ), |
| 1780 | ), |
| 1781 | ), |
| 1782 | ], |
| 1783 | ); |
| 1784 | } |
| 1785 | |
| 1786 | Widget _buildTimezonePill({ |
| 1787 | required BuildContext context, |
| 1788 | required RouteInfoEntity arrival, |
| 1789 | required RouteInfoEntity departure, |
| 1790 | }) { |
| 1791 | final arrivalTime = _resolveEventTime(arrival) |
| 1792 | if (arrivalTime == null) { |
| 1793 | return const SizedBox |
| 1794 | } |
| 1795 | |
| 1796 | final use24Hrs = MediaQuery. |
| 1797 | final arrivalTz = _sanitizeTimezone(arrival |
| 1798 | final departureTz = _sanitizeTimezone(departure |
| 1799 | final arrivalLocal = |
| 1800 | arrivalTime.toTimezoneString(arrivalTz, use24Hrs: use24Hrs) |
| 1801 | final arrivalInDeparture = |
| 1802 | arrivalTime.toTimezoneString(departureTz, use24Hrs: use24Hrs) |
| 1803 | final diff = getTimezoneDifference(arrivalTz |
| 1804 | |
| 1805 | final arrivalLabel = _formatAirportLabel(arrival |
| 1806 | final departureLabel = _formatAirportLabel(departure |
| 1807 | |
| 1808 | final diffTitle = _formatDiffTitle(diff) |
| 1809 | final subtitle = diff == 'same timezone' |
| 1810 | ? "$arrivalLocal arrival in $ |
| 1811 | : "$arrivalLocal arrival in $ |
| 1812 | |
| 1813 | final theme = Theme. |
| 1814 | |
| 1815 | return Container( |
| 1816 | padding: const EdgeInsets. |
| 1817 | decoration: BoxDecoration( |
| 1818 | borderRadius: BorderRadius.circular( |
| 1819 | border: Border.all( |
| 1820 | color: theme.dividerColor.withValues(alpha |
| 1821 | ), |
| 1822 | ), |
| 1823 | child: Row( |
| 1824 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1825 | children: [ |
| 1826 | Container( |
| 1827 | width: 32, |
| 1828 | height: 32, |
| 1829 | decoration: BoxDecoration( |
| 1830 | color: theme.colorScheme.primary.withValues |
| 1831 | borderRadius: BorderRadius.circular( |
| 1832 | ), |
| 1833 | child: Icon( |
| 1834 | Symbols.schedule, |
| 1835 | size: 18, |
| 1836 | ), |
| 1837 | ), |
| 1838 | const SizedBox(width: |
| 1839 | Expanded( |
| 1840 | child: Column( |
| 1841 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1842 | spacing: 4, |
| 1843 | children: [ |
| 1844 | Text( |
| 1845 | diffTitle, |
| 1846 | style: const TextStyle( |
| 1847 | fontWeight: FontWeight.w700, |
| 1848 | ), |
| 1849 | ), |
| 1850 | Text( |
| 1851 | subtitle, |
| 1852 | style: TextStyle( |
| 1853 | color: theme.textTheme.bodySmall?.color |
| 1854 | alpha: theme.brightness == Brightness |
| 1855 | ), |
| 1856 | ), |
| 1857 | ], |
| 1858 | ), |
| 1859 | ), |
| 1860 | ], |
| 1861 | ), |
| 1862 | ); |
| 1863 | } |
| 1864 | |
| 1865 | Widget _buildCodesharePill( |
| 1866 | BuildContext context, |
| 1867 | List<String> codeshares, |
| 1868 | ) { |
| 1869 | final theme = Theme. |
| 1870 | |
| 1871 | return Container( |
| 1872 | padding: const EdgeInsets. |
| 1873 | decoration: BoxDecoration( |
| 1874 | borderRadius: BorderRadius.circular( |
| 1875 | border: Border.all( |
| 1876 | color: theme.dividerColor.withValues(alpha |
| 1877 | ), |
| 1878 | ), |
| 1879 | child: Row( |
| 1880 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1881 | children: [ |
| 1882 | Container( |
| 1883 | width: 32, |
| 1884 | height: 32, |
| 1885 | decoration: BoxDecoration( |
| 1886 | color: theme.colorScheme.secondary.withValues |
| 1887 | borderRadius: BorderRadius.circular( |
| 1888 | ), |
| 1889 | child: Icon( |
| 1890 | Icons.flight_takeoff, |
| 1891 | size: 18, |
| 1892 | color: theme.colorScheme.secondary, |
| 1893 | ), |
| 1894 | ), |
| 1895 | const SizedBox(width: |
| 1896 | Expanded( |
| 1897 | child: Column( |
| 1898 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1899 | spacing: 6, |
| 1900 | children: [ |
| 1901 | const Text( |
| 1902 | "Codeshare flight", |
| 1903 | style: TextStyle(fontWeight: FontWeight |
| 1904 | ), |
| 1905 | Text( |
| 1906 | "Also sold as ${codeshares.join( |
| 1907 | style: TextStyle( |
| 1908 | color: theme.textTheme.bodySmall?.color |
| 1909 | alpha: theme.brightness == Brightness |
| 1910 | ), |
| 1911 | ), |
| 1912 | Text( |
| 1913 | "Same aircraft, different partner airline numbers.", |
| 1914 | style: TextStyle( |
| 1915 | fontSize: 12, |
| 1916 | color: theme.textTheme.bodySmall?.color |
| 1917 | alpha: theme.brightness == Brightness |
| 1918 | ), |
| 1919 | ), |
| 1920 | ], |
| 1921 | ), |
| 1922 | ), |
| 1923 | ], |
| 1924 | ), |
| 1925 | ); |
| 1926 | } |
| 1927 | |
| 1928 | DateTime? _resolveEventTime(RouteInfoEntity |
| 1929 | final candidate = |
| 1930 | segment.revisedTime ?? segment.predictedTime ?? segment. |
| 1931 | try { |
| 1932 | return DateTime.parse |
| 1933 | } catch (_) { |
| 1934 | return null; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | String _formatAirportLabel(RouteAirportEntity |
| 1939 | final code = _airportCode(airport) |
| 1940 | if (code.isEmpty) return airport. |
| 1941 | return "${airport. |
| 1942 | } |
| 1943 | |
| 1944 | String _airportCode(RouteAirportEntity |
| 1945 | return airport.iata.isNotEmpty ? |
| 1946 | } |
| 1947 | |
| 1948 | String _sanitizeTimezone(String |
| 1949 | return timezone.trim(). |
| 1950 | } |
| 1951 | |
| 1952 | String _formatDiffTitle(String |
| 1953 | if (diff == 'same timezone') { |
| 1954 | return "No Timezone Change"; |
| 1955 | } |
| 1956 | final sign = diff.startsWith |
| 1957 | final remainder = diff.substring |
| 1958 | final normalized = remainder |
| 1959 | .replaceAll('hrs', 'Hours' |
| 1960 | .replaceAll('hr', 'Hour' |
| 1961 | .replaceAll('mins', 'Minutes' |
| 1962 | .replaceAll('min', 'Minute' |
| 1963 | return "$sign$ |
| 1964 | } |
| 1965 | |
| 1966 | String _airportCity(RouteAirportEntity |
| 1967 | return airport.municipalityName.isNotEmpty |
| 1968 | ? airport.municipalityName |
| 1969 | : airport.shortName ?? airport.name; |
| 1970 | } |
| 1971 | |
| 1972 | Duration? _calculateDelay(dynamic |
| 1973 | if (revisedTime != null && scheduledTime != |
| 1974 | return getDelay( |
| 1975 | DateTime.parse(scheduledTime.utc |
| 1976 | DateTime.parse(revisedTime.utc |
| 1977 | ); |
| 1978 | } |
| 1979 | return null; |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | Duration getDelay(DateTime scheduled |
| 1984 | // Positive duration => delayed; negative duration => early; zero => on time |
| 1985 | return predicted.difference(scheduled); |
| 1986 | } |
| 1987 | |
| 1988 | DateTime convertToArrivalTimeZone( |
| 1989 | DateTime departureTime, |
| 1990 | String departureTimeZone, |
| 1991 | String arrivalTimeZone, |
| 1992 | ) { |
| 1993 | try { |
| 1994 | tz.initializeTimeZones(); |
| 1995 | } catch (e) { |
| 1996 | print(e); |
| 1997 | } |
| 1998 | // Initialize time zone locations |
| 1999 | final departureLocation = tz.getLocation |
| 2000 | final arrivalLocation = tz.getLocation |
| 2001 | |
| 2002 | // Convert departure time to TZDateTime in the departure location |
| 2003 | final departureTZTime = tz.TZDateTime |
| 2004 | |
| 2005 | // Convert the departure TZDateTime to the arrival time zone |
| 2006 | final arrivalTZTime = tz.TZDateTime |
| 2007 | |
| 2008 | return arrivalTZTime.toLocal(); |
| 2009 | } |
| 2010 | |
| 2011 | String formatAge(double age) { |
| 2012 | if (age == 0) return |
| 2013 | |
| 2014 | final years = age.floor |
| 2015 | final months = ((age - years) * |
| 2016 | |
| 2017 | final List<String |
| 2018 | |
| 2019 | if (years > 0) { |
| 2020 | parts.add('$years |
| 2021 | } |
| 2022 | |
| 2023 | if (months > 0) { |
| 2024 | parts.add('$months |
| 2025 | } |
| 2026 | |
| 2027 | return parts.join(' and ' |
| 2028 | } |
| 2029 | |
| 2030 | String formatDate(DateTime date) { |
| 2031 | return '${MONTHS[ |
| 2032 | } |
| 2033 | |
| 2034 | // ignore: unused_element |
| 2035 | class _ChartPosition { |
| 2036 | final double altitude; |
| 2037 | final double speed; |
| 2038 | final DateTime timestamp; |
| 2039 | |
| 2040 | _ChartPosition({ |
| 2041 | required this.altitude, |
| 2042 | required this.speed, |
| 2043 | required this.timestamp, |
| 2044 | }); |
| 2045 | } |