| 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:openapi/openapi.dart'; |
| 6 | import 'package:plane_pal/services/profile.dart'; |
| 7 | |
| 8 | class FlightStatsScreen extends StatefulWidget |
| 9 | const FlightStatsScreen({super |
| 10 | |
| 11 | @override |
| 12 | State<FlightStatsScreen> createState |
| 13 | } |
| 14 | |
| 15 | class _FlightStatsScreenState extends State |
| 16 | final ProfileService _profileService = |
| 17 | ProfileStatsResponseEntity? _stats; |
| 18 | bool _isLoading = true; |
| 19 | String? _error; |
| 20 | |
| 21 | @override |
| 22 | void initState() { |
| 23 | super.initState(); |
| 24 | _loadStats(); |
| 25 | } |
| 26 | |
| 27 | Future<void> _loadStats |
| 28 | setState(() { |
| 29 | _isLoading = true; |
| 30 | _error = null; |
| 31 | }); |
| 32 | |
| 33 | try { |
| 34 | final stats = await _profileService. |
| 35 | setState(() { |
| 36 | _stats = stats; |
| 37 | _isLoading = false; |
| 38 | }); |
| 39 | } catch (e) { |
| 40 | print(e); |
| 41 | |
| 42 | setState(() { |
| 43 | _error = e.toString(); |
| 44 | _isLoading = false; |
| 45 | }); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | @override |
| 50 | Widget build(BuildContext |
| 51 | final theme = Theme. |
| 52 | final colorScheme = theme.colorScheme; |
| 53 | |
| 54 | return Scaffold( |
| 55 | backgroundColor: colorScheme.surface, |
| 56 | appBar: AppBar( |
| 57 | elevation: 0, |
| 58 | backgroundColor: colorScheme.surface, |
| 59 | ), |
| 60 | body: SafeArea( |
| 61 | child: _isLoading |
| 62 | ? Center( |
| 63 | child: CircularProgressIndicator( |
| 64 | color: colorScheme.primary, |
| 65 | ), |
| 66 | ) |
| 67 | : _error != null |
| 68 | ? Center( |
| 69 | child: Column( |
| 70 | mainAxisAlignment: MainAxisAlignment.center, |
| 71 | children: [ |
| 72 | Text( |
| 73 | 'Error loading stats', |
| 74 | style: TextStyle(color: colorScheme. |
| 75 | ), |
| 76 | const Gap(8) |
| 77 | ElevatedButton( |
| 78 | onPressed: _loadStats, |
| 79 | child: const Text( |
| 80 | ), |
| 81 | ], |
| 82 | ), |
| 83 | ) |
| 84 | : _stats == null |
| 85 | ? Center( |
| 86 | child: Text( |
| 87 | 'No stats available', |
| 88 | style: TextStyle(color: colorScheme. |
| 89 | ), |
| 90 | ) |
| 91 | : SingleChildScrollView( |
| 92 | padding: const EdgeInsets. |
| 93 | horizontal: 20, vertical: 16) |
| 94 | child: Column( |
| 95 | crossAxisAlignment: CrossAxisAlignment.start, |
| 96 | children: [ |
| 97 | // Passport Stats Grid |
| 98 | _buildPassportGrid(_stats!.passport), |
| 99 | const Gap(40) |
| 100 | |
| 101 | // Flight Distance Section |
| 102 | _buildFlightDistanceSection(), |
| 103 | const Gap(40) |
| 104 | |
| 105 | // Flight Time Section |
| 106 | _buildFlightTimeSection(), |
| 107 | const Gap(40) |
| 108 | |
| 109 | // Aircraft Stats |
| 110 | if (_stats!.aircraftStats != null) |
| 111 | _buildAircraftStatsSection( |
| 112 | _stats!.aircraftStats!), |
| 113 | if (_stats!.aircraftStats != null) |
| 114 | |
| 115 | // Top Airlines |
| 116 | if (_stats!.airlines.isNotEmpty) |
| 117 | _buildTopAirlinesSection( |
| 118 | _stats!.airlines.toList()), |
| 119 | if (_stats!.airlines.isNotEmpty) const |
| 120 | |
| 121 | // Top Airports |
| 122 | if (_stats!.airports.isNotEmpty) |
| 123 | _buildTopAirportsSection( |
| 124 | _stats!.airports.toList()), |
| 125 | if (_stats!.airports.isNotEmpty) const |
| 126 | |
| 127 | // Top Routes |
| 128 | if (_stats!.topRoutes.isNotEmpty) |
| 129 | _buildTopRoutesSection( |
| 130 | _stats!.topRoutes.toList()), |
| 131 | const Gap(20) |
| 132 | ], |
| 133 | ), |
| 134 | ), |
| 135 | ), |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | Widget _buildPassportGrid(PassportEntity |
| 140 | final theme = Theme. |
| 141 | final colorScheme = theme.colorScheme; |
| 142 | |
| 143 | return Column( |
| 144 | crossAxisAlignment: CrossAxisAlignment.start, |
| 145 | children: [ |
| 146 | Text( |
| 147 | 'MY STATS', |
| 148 | style: TextStyle( |
| 149 | fontSize: 24, |
| 150 | fontWeight: FontWeight.w700, |
| 151 | color: colorScheme.onSurface, |
| 152 | letterSpacing: 0.5, |
| 153 | ), |
| 154 | ), |
| 155 | const Gap(6) |
| 156 | Text( |
| 157 | 'FLIGHT STATISTICS', |
| 158 | style: TextStyle( |
| 159 | fontSize: 12, |
| 160 | color: colorScheme.onSurfaceVariant, |
| 161 | letterSpacing: 0.5, |
| 162 | fontWeight: FontWeight.w500, |
| 163 | ), |
| 164 | ), |
| 165 | const Gap(20) |
| 166 | Row( |
| 167 | children: [ |
| 168 | Expanded( |
| 169 | child: _buildStatCard('FLIGHTS', |
| 170 | ), |
| 171 | const Gap(12) |
| 172 | Expanded( |
| 173 | child: _buildStatCard( |
| 174 | 'FLIGHT TIME', |
| 175 | '${(passport.totalDurationMinutes / |
| 176 | ), |
| 177 | ), |
| 178 | ], |
| 179 | ), |
| 180 | const Gap(12) |
| 181 | Row( |
| 182 | children: [ |
| 183 | Expanded( |
| 184 | child: _buildStatCard( |
| 185 | 'DISTANCE', |
| 186 | '${passport.totalDistanceKm. |
| 187 | ), |
| 188 | ), |
| 189 | const Gap(12) |
| 190 | Expanded( |
| 191 | child: _buildStatCard('AIRPORTS', |
| 192 | ), |
| 193 | ], |
| 194 | ), |
| 195 | const Gap(12) |
| 196 | Row( |
| 197 | children: [ |
| 198 | Expanded( |
| 199 | child: _buildStatCard('AIRLINES', |
| 200 | ), |
| 201 | const Gap(12) |
| 202 | Expanded( |
| 203 | child: Container(), |
| 204 | ), |
| 205 | ], |
| 206 | ), |
| 207 | ], |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | Widget _buildStatCard(String |
| 212 | final theme = Theme. |
| 213 | final colorScheme = theme.colorScheme; |
| 214 | |
| 215 | return Container( |
| 216 | padding: const EdgeInsets. |
| 217 | decoration: BoxDecoration( |
| 218 | color: colorScheme.surfaceVariant, |
| 219 | borderRadius: BorderRadius.circular( |
| 220 | ), |
| 221 | child: Column( |
| 222 | crossAxisAlignment: CrossAxisAlignment.start, |
| 223 | mainAxisAlignment: MainAxisAlignment.center, |
| 224 | children: [ |
| 225 | Text( |
| 226 | label, |
| 227 | style: TextStyle( |
| 228 | fontSize: 11, |
| 229 | color: colorScheme.onSurfaceVariant, |
| 230 | fontWeight: FontWeight.w600, |
| 231 | letterSpacing: 0.5, |
| 232 | ), |
| 233 | ), |
| 234 | const Gap(8) |
| 235 | Text( |
| 236 | value, |
| 237 | style: TextStyle( |
| 238 | fontSize: 20, |
| 239 | fontWeight: FontWeight.w700, |
| 240 | color: colorScheme.onSurface, |
| 241 | height: 1.2, |
| 242 | ), |
| 243 | overflow: TextOverflow.ellipsis, |
| 244 | maxLines: 2, |
| 245 | ), |
| 246 | ], |
| 247 | ), |
| 248 | ); |
| 249 | } |
| 250 | |
| 251 | Widget _buildFlightDistanceSection() { |
| 252 | if (_stats == null) return |
| 253 | |
| 254 | final theme = Theme. |
| 255 | final colorScheme = theme.colorScheme; |
| 256 | |
| 257 | final totalDistance = _stats!.passport |
| 258 | final avgDistance = _stats!.passport |
| 259 | ? totalDistance / _stats!.passport.totalFlights |
| 260 | : 0.0; |
| 261 | |
| 262 | // Calculate comparisons |
| 263 | final earthCircumference = 40075.0; |
| 264 | final moonDistance = 384400.0; |
| 265 | final marsDistance = 54600000.0; |
| 266 | |
| 267 | final aroundEarth = totalDistance / earthCircumference; |
| 268 | final toMoon = totalDistance / moonDistance; |
| 269 | final toMars = totalDistance / marsDistance; |
| 270 | |
| 271 | return Column( |
| 272 | crossAxisAlignment: CrossAxisAlignment.start, |
| 273 | children: [ |
| 274 | Text( |
| 275 | 'Flight Distance', |
| 276 | style: TextStyle( |
| 277 | fontSize: 20, |
| 278 | fontWeight: FontWeight.w700, |
| 279 | color: colorScheme.onSurface, |
| 280 | ), |
| 281 | ), |
| 282 | const Gap(16) |
| 283 | Text( |
| 284 | '${totalDistance.toStringAsFixed( |
| 285 | style: TextStyle( |
| 286 | fontSize: 32, |
| 287 | fontWeight: FontWeight.w700, |
| 288 | color: colorScheme.onSurface, |
| 289 | height: 1.2, |
| 290 | ), |
| 291 | ), |
| 292 | const Gap(4) |
| 293 | Text( |
| 294 | '${(totalDistance * 0.621371).toStringAsFixed |
| 295 | style: TextStyle( |
| 296 | fontSize: 14, |
| 297 | color: colorScheme.onSurfaceVariant, |
| 298 | fontWeight: FontWeight.w500, |
| 299 | ), |
| 300 | ), |
| 301 | const Gap(8) |
| 302 | Text( |
| 303 | 'Average: ${avgDistance.toStringAsFixed( |
| 304 | style: TextStyle( |
| 305 | fontSize: 13, |
| 306 | color: colorScheme.onSurfaceVariant, |
| 307 | fontWeight: FontWeight.w500, |
| 308 | ), |
| 309 | ), |
| 310 | const Gap(24) |
| 311 | // Comparisons |
| 312 | _buildComparisonBar( |
| 313 | Icons.public, |
| 314 | colorScheme.primary, |
| 315 | 'Around Earth', |
| 316 | aroundEarth, |
| 317 | '${aroundEarth.toStringAsFixed( |
| 318 | ), |
| 319 | const Gap(12) |
| 320 | _buildComparisonBar( |
| 321 | Icons.nightlight_round, |
| 322 | colorScheme.secondary, |
| 323 | 'To the Moon', |
| 324 | toMoon, |
| 325 | '${toMoon.toStringAsFixed( |
| 326 | ), |
| 327 | const Gap(12) |
| 328 | _buildComparisonBar( |
| 329 | Icons.rocket_launch, |
| 330 | colorScheme.tertiary, |
| 331 | 'To Mars', |
| 332 | toMars, |
| 333 | '${toMars.toStringAsFixed( |
| 334 | ), |
| 335 | const Gap(24) |
| 336 | // Shortest and Longest |
| 337 | _buildFlightRecord( |
| 338 | 'Shortest flight', |
| 339 | _stats!.shortestDistanceFlight, |
| 340 | true, |
| 341 | ), |
| 342 | const Gap(16) |
| 343 | _buildFlightRecord( |
| 344 | 'Longest flight', |
| 345 | _stats!.longestDistanceFlight, |
| 346 | true, |
| 347 | ), |
| 348 | ], |
| 349 | ); |
| 350 | } |
| 351 | |
| 352 | Widget _buildComparisonBar( |
| 353 | IconData icon, |
| 354 | Color iconColor, |
| 355 | String label, |
| 356 | double value, |
| 357 | String text, |
| 358 | ) { |
| 359 | final theme = Theme. |
| 360 | final colorScheme = theme.colorScheme; |
| 361 | |
| 362 | // Use different max values based on the comparison type |
| 363 | // For Mars, use a much smaller max value since distances are very small |
| 364 | final maxValue = label == 'To Mars' |
| 365 | final normalizedValue = (value / maxValue). |
| 366 | |
| 367 | return Container( |
| 368 | padding: const EdgeInsets. |
| 369 | decoration: BoxDecoration( |
| 370 | color: colorScheme.surfaceVariant, |
| 371 | borderRadius: BorderRadius.circular( |
| 372 | ), |
| 373 | child: Row( |
| 374 | children: [ |
| 375 | Container( |
| 376 | width: 40, |
| 377 | height: 40, |
| 378 | decoration: BoxDecoration( |
| 379 | color: iconColor.withOpacity(0.15) |
| 380 | shape: BoxShape.circle, |
| 381 | ), |
| 382 | child: Icon(icon, color: |
| 383 | ), |
| 384 | const Gap(12) |
| 385 | Expanded( |
| 386 | child: Column( |
| 387 | crossAxisAlignment: CrossAxisAlignment.start, |
| 388 | children: [ |
| 389 | Text( |
| 390 | label, |
| 391 | style: TextStyle( |
| 392 | color: colorScheme.onSurfaceVariant, |
| 393 | fontWeight: FontWeight.w500, |
| 394 | fontSize: 13, |
| 395 | ), |
| 396 | ), |
| 397 | const Gap(6) |
| 398 | Row( |
| 399 | children: [ |
| 400 | Expanded( |
| 401 | child: Container( |
| 402 | height: 6, |
| 403 | decoration: BoxDecoration( |
| 404 | color: colorScheme.surface, |
| 405 | borderRadius: BorderRadius.circular( |
| 406 | ), |
| 407 | child: FractionallySizedBox( |
| 408 | alignment: Alignment.centerLeft, |
| 409 | widthFactor: normalizedValue, |
| 410 | child: Container( |
| 411 | decoration: BoxDecoration( |
| 412 | color: iconColor, |
| 413 | borderRadius: BorderRadius.circular( |
| 414 | ), |
| 415 | ), |
| 416 | ), |
| 417 | ), |
| 418 | ), |
| 419 | const Gap(12) |
| 420 | Text( |
| 421 | text, |
| 422 | style: TextStyle( |
| 423 | color: colorScheme.onSurface, |
| 424 | fontWeight: FontWeight.w700, |
| 425 | fontSize: 13, |
| 426 | ), |
| 427 | ), |
| 428 | ], |
| 429 | ), |
| 430 | ], |
| 431 | ), |
| 432 | ), |
| 433 | ], |
| 434 | ), |
| 435 | ); |
| 436 | } |
| 437 | |
| 438 | Widget _buildFlightTimeSection() { |
| 439 | if (_stats == null) return |
| 440 | |
| 441 | final theme = Theme. |
| 442 | final colorScheme = theme.colorScheme; |
| 443 | |
| 444 | final totalMinutes = _stats!.passport |
| 445 | final hours = (totalMinutes / 60 |
| 446 | final minutes = (totalMinutes % 60 |
| 447 | final days = (hours / 24 |
| 448 | final weeks = (days / 7 |
| 449 | final months = (days / 30 |
| 450 | final years = (days / 365 |
| 451 | |
| 452 | final avgMinutes = _stats!.passport |
| 453 | ? totalMinutes / _stats!.passport.totalFlights |
| 454 | : 0.0; |
| 455 | final avgHours = (avgMinutes / 60 |
| 456 | final avgMins = (avgMinutes % 60 |
| 457 | |
| 458 | return Column( |
| 459 | crossAxisAlignment: CrossAxisAlignment.start, |
| 460 | children: [ |
| 461 | Text( |
| 462 | 'Flight Time', |
| 463 | style: TextStyle( |
| 464 | fontSize: 20, |
| 465 | fontWeight: FontWeight.w700, |
| 466 | color: colorScheme.onSurface, |
| 467 | ), |
| 468 | ), |
| 469 | const Gap(16) |
| 470 | Text( |
| 471 | '${hours}h ${minutes |
| 472 | style: TextStyle( |
| 473 | fontSize: 32, |
| 474 | fontWeight: FontWeight.w700, |
| 475 | color: colorScheme.onSurface, |
| 476 | height: 1.2, |
| 477 | ), |
| 478 | ), |
| 479 | const Gap(20) |
| 480 | // Stats Grid |
| 481 | Row( |
| 482 | children: [ |
| 483 | Expanded( |
| 484 | child: Column( |
| 485 | children: [ |
| 486 | _buildTimeStat('Days', days.toStringAsFixed |
| 487 | const Gap(12) |
| 488 | _buildTimeStat('Weeks', weeks.toStringAsFixed |
| 489 | const Gap(12) |
| 490 | _buildTimeStat('Months', months.toStringAsFixed |
| 491 | ], |
| 492 | ), |
| 493 | ), |
| 494 | const Gap(12) |
| 495 | Expanded( |
| 496 | child: Column( |
| 497 | children: [ |
| 498 | _buildTimeStat('Years', years.toStringAsFixed |
| 499 | const Gap(12) |
| 500 | _buildTimeStat('Avg. Flight', '${ |
| 501 | const Gap(12) |
| 502 | _buildTimeStat('Total Hours', '${ |
| 503 | ], |
| 504 | ), |
| 505 | ), |
| 506 | ], |
| 507 | ), |
| 508 | const Gap(24) |
| 509 | // Shortest and Longest |
| 510 | _buildFlightRecord( |
| 511 | 'Shortest flight', |
| 512 | _stats!.shortestDurationFlight, |
| 513 | false, |
| 514 | ), |
| 515 | const Gap(16) |
| 516 | _buildFlightRecord( |
| 517 | 'Longest flight', |
| 518 | _stats!.longestDurationFlight, |
| 519 | false, |
| 520 | ), |
| 521 | ], |
| 522 | ); |
| 523 | } |
| 524 | |
| 525 | Widget _buildTimeStat(String |
| 526 | final theme = Theme. |
| 527 | final colorScheme = theme.colorScheme; |
| 528 | |
| 529 | return Container( |
| 530 | padding: const EdgeInsets. |
| 531 | decoration: BoxDecoration( |
| 532 | color: colorScheme.surfaceVariant, |
| 533 | borderRadius: BorderRadius.circular( |
| 534 | ), |
| 535 | child: Column( |
| 536 | crossAxisAlignment: CrossAxisAlignment.stretch, |
| 537 | mainAxisAlignment: MainAxisAlignment.center, |
| 538 | children: [ |
| 539 | Text( |
| 540 | label, |
| 541 | style: TextStyle( |
| 542 | fontSize: 11, |
| 543 | color: colorScheme.onSurfaceVariant, |
| 544 | fontWeight: FontWeight.w500, |
| 545 | ), |
| 546 | ), |
| 547 | const Gap(4) |
| 548 | Text( |
| 549 | value, |
| 550 | style: TextStyle( |
| 551 | fontSize: 15, |
| 552 | fontWeight: FontWeight.w700, |
| 553 | color: colorScheme.onSurface, |
| 554 | ), |
| 555 | ), |
| 556 | ], |
| 557 | ), |
| 558 | ); |
| 559 | } |
| 560 | |
| 561 | Widget _buildFlightRecord(String |
| 562 | final theme = Theme. |
| 563 | final colorScheme = theme.colorScheme; |
| 564 | |
| 565 | String value; |
| 566 | String route; |
| 567 | String flightInfo; |
| 568 | |
| 569 | if (isDistance && flight is FlightDistanceEntity |
| 570 | value = '${flight.distanceKm |
| 571 | route = |
| 572 | '${flight.flight. |
| 573 | flightInfo = '${flight.flight |
| 574 | } else if (!isDistance && flight is |
| 575 | final hours = (flight.durationMinutes / |
| 576 | final minutes = (flight.durationMinutes % |
| 577 | value = '${hours}h |
| 578 | route = |
| 579 | '${flight.flight. |
| 580 | flightInfo = '${flight.flight |
| 581 | } else { |
| 582 | return const SizedBox |
| 583 | } |
| 584 | |
| 585 | return Container( |
| 586 | padding: const EdgeInsets. |
| 587 | decoration: BoxDecoration( |
| 588 | color: colorScheme.surfaceVariant, |
| 589 | borderRadius: BorderRadius.circular( |
| 590 | ), |
| 591 | child: Row( |
| 592 | children: [ |
| 593 | Container( |
| 594 | width: 44, |
| 595 | height: 44, |
| 596 | decoration: BoxDecoration( |
| 597 | color: colorScheme.primaryContainer, |
| 598 | borderRadius: BorderRadius.circular( |
| 599 | ), |
| 600 | child: Icon( |
| 601 | Icons.flight, |
| 602 | color: colorScheme.primary, |
| 603 | size: 22, |
| 604 | ), |
| 605 | ), |
| 606 | const Gap(12) |
| 607 | Expanded( |
| 608 | child: Column( |
| 609 | crossAxisAlignment: CrossAxisAlignment.start, |
| 610 | children: [ |
| 611 | Text( |
| 612 | title, |
| 613 | style: TextStyle( |
| 614 | fontSize: 11, |
| 615 | color: colorScheme.onSurfaceVariant, |
| 616 | fontWeight: FontWeight.w600, |
| 617 | letterSpacing: 0.3, |
| 618 | ), |
| 619 | ), |
| 620 | const Gap(4) |
| 621 | Text( |
| 622 | route, |
| 623 | style: TextStyle( |
| 624 | fontSize: 14, |
| 625 | fontWeight: FontWeight.w600, |
| 626 | color: colorScheme.onSurface, |
| 627 | ), |
| 628 | maxLines: 1, |
| 629 | overflow: TextOverflow.ellipsis, |
| 630 | ), |
| 631 | const Gap(2) |
| 632 | Text( |
| 633 | flightInfo, |
| 634 | style: TextStyle( |
| 635 | fontSize: 12, |
| 636 | color: colorScheme.onSurfaceVariant, |
| 637 | fontWeight: FontWeight.w500, |
| 638 | ), |
| 639 | overflow: TextOverflow.ellipsis, |
| 640 | maxLines: 1, |
| 641 | ), |
| 642 | ], |
| 643 | ), |
| 644 | ), |
| 645 | const Gap(12) |
| 646 | Text( |
| 647 | value, |
| 648 | style: TextStyle( |
| 649 | fontSize: 16, |
| 650 | fontWeight: FontWeight.w700, |
| 651 | color: colorScheme.onSurface, |
| 652 | ), |
| 653 | ), |
| 654 | ], |
| 655 | ), |
| 656 | ); |
| 657 | } |
| 658 | |
| 659 | Widget _buildAircraftStatsSection(AircraftStatsEntity |
| 660 | final theme = Theme. |
| 661 | final colorScheme = theme.colorScheme; |
| 662 | |
| 663 | return Column( |
| 664 | crossAxisAlignment: CrossAxisAlignment.start, |
| 665 | children: [ |
| 666 | Row( |
| 667 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 668 | children: [ |
| 669 | Text( |
| 670 | 'Aircraft Stats', |
| 671 | style: TextStyle( |
| 672 | fontSize: 20, |
| 673 | fontWeight: FontWeight.w700, |
| 674 | color: colorScheme.onSurface, |
| 675 | ), |
| 676 | ), |
| 677 | TextButton( |
| 678 | onPressed: () { |
| 679 | _showAircraftStatsBottomSheet(aircraftStats); |
| 680 | }, |
| 681 | child: Text( |
| 682 | 'View Details', |
| 683 | style: TextStyle( |
| 684 | fontSize: 13, |
| 685 | fontWeight: FontWeight.w600, |
| 686 | ), |
| 687 | ), |
| 688 | ), |
| 689 | ], |
| 690 | ), |
| 691 | const Gap(16) |
| 692 | // Most Flown Aircraft - Large image with overlay |
| 693 | if (aircraftStats.mostFlownAircraftName.isNotEmpty) |
| 694 | GestureDetector( |
| 695 | onTap: () { |
| 696 | _showAircraftStatsBottomSheet(aircraftStats); |
| 697 | }, |
| 698 | child: _buildAircraftImageCard( |
| 699 | aircraftStats.mostFlownAircraftName, |
| 700 | aircraftStats.mostFlownAircraftFlightCount.toInt(), |
| 701 | aircraftStats.mostFlownAircraftImage, |
| 702 | ), |
| 703 | ), |
| 704 | ], |
| 705 | ); |
| 706 | } |
| 707 | |
| 708 | Widget _buildAircraftImageCard( |
| 709 | String aircraftName, |
| 710 | int flightCount, |
| 711 | String? imageUrl, |
| 712 | ) { |
| 713 | final theme = Theme. |
| 714 | final colorScheme = theme.colorScheme; |
| 715 | |
| 716 | return Container( |
| 717 | width: double.infinity, |
| 718 | height: 300, |
| 719 | decoration: BoxDecoration( |
| 720 | color: colorScheme.surfaceVariant, |
| 721 | borderRadius: BorderRadius.circular( |
| 722 | boxShadow: [ |
| 723 | BoxShadow( |
| 724 | color: Colors.black.withOpacity |
| 725 | blurRadius: 8, |
| 726 | offset: const Offset( |
| 727 | ), |
| 728 | ], |
| 729 | ), |
| 730 | child: ClipRRect( |
| 731 | borderRadius: BorderRadius.circular( |
| 732 | child: Stack( |
| 733 | fit: StackFit.expand, |
| 734 | children: [ |
| 735 | if (imageUrl != null && imageUrl. |
| 736 | imageUrl.endsWith('.svg') |
| 737 | ? SvgPicture.network( |
| 738 | imageUrl, |
| 739 | fit: BoxFit.contain, |
| 740 | placeholderBuilder: (context) => Container( |
| 741 | color: colorScheme.surfaceVariant, |
| 742 | child: Center( |
| 743 | child: Icon( |
| 744 | Icons.flight, |
| 745 | color: colorScheme.onSurfaceVariant, |
| 746 | size: 64, |
| 747 | ), |
| 748 | ), |
| 749 | ), |
| 750 | ) |
| 751 | : CachedNetworkImage( |
| 752 | imageUrl: imageUrl, |
| 753 | placeholder: (context, url) => Container |
| 754 | color: colorScheme.surfaceVariant, |
| 755 | child: Center( |
| 756 | child: CircularProgressIndicator( |
| 757 | color: colorScheme.primary, |
| 758 | ), |
| 759 | ), |
| 760 | ), |
| 761 | errorWidget: (context, url, error) => Container |
| 762 | color: colorScheme.surfaceVariant, |
| 763 | child: Center( |
| 764 | child: Icon( |
| 765 | Icons.flight, |
| 766 | color: colorScheme.onSurfaceVariant, |
| 767 | size: 64, |
| 768 | ), |
| 769 | ), |
| 770 | ), |
| 771 | ) |
| 772 | else |
| 773 | Container( |
| 774 | color: colorScheme.surfaceVariant, |
| 775 | child: Center( |
| 776 | child: Icon( |
| 777 | Icons.flight, |
| 778 | color: colorScheme.onSurfaceVariant, |
| 779 | size: 64, |
| 780 | ), |
| 781 | ), |
| 782 | ), |
| 783 | Container( |
| 784 | decoration: BoxDecoration( |
| 785 | gradient: LinearGradient( |
| 786 | begin: Alignment.topCenter, |
| 787 | end: Alignment.bottomCenter, |
| 788 | colors: [ |
| 789 | Colors.transparent, |
| 790 | Colors.black.withOpacity( |
| 791 | ], |
| 792 | ), |
| 793 | ), |
| 794 | ), |
| 795 | Positioned( |
| 796 | bottom: 0, |
| 797 | left: 0, |
| 798 | right: 0, |
| 799 | child: Padding( |
| 800 | padding: const EdgeInsets. |
| 801 | child: Column( |
| 802 | crossAxisAlignment: CrossAxisAlignment.start, |
| 803 | mainAxisSize: MainAxisSize.min, |
| 804 | children: [ |
| 805 | Text( |
| 806 | aircraftName, |
| 807 | style: const TextStyle( |
| 808 | fontSize: 24, |
| 809 | fontWeight: FontWeight.bold, |
| 810 | color: Colors.white, |
| 811 | shadows: [ |
| 812 | Shadow( |
| 813 | offset: Offset(0, |
| 814 | blurRadius: 3, |
| 815 | color: Colors.black54, |
| 816 | ), |
| 817 | ], |
| 818 | ), |
| 819 | ), |
| 820 | const Gap(8) |
| 821 | Row( |
| 822 | children: [ |
| 823 | Icon( |
| 824 | Icons.flight_takeoff, |
| 825 | color: Colors.white.withOpacity |
| 826 | size: 18, |
| 827 | ), |
| 828 | const Gap(6) |
| 829 | Text( |
| 830 | '$flightCount ${flightCount |
| 831 | style: TextStyle( |
| 832 | fontSize: 16, |
| 833 | fontWeight: FontWeight.w600, |
| 834 | color: Colors.white.withOpacity |
| 835 | shadows: const [ |
| 836 | Shadow( |
| 837 | offset: Offset(0, |
| 838 | blurRadius: 3, |
| 839 | color: Colors.black54, |
| 840 | ), |
| 841 | ], |
| 842 | ), |
| 843 | ), |
| 844 | ], |
| 845 | ), |
| 846 | ], |
| 847 | ), |
| 848 | ), |
| 849 | ), |
| 850 | Positioned( |
| 851 | top: 16, |
| 852 | right: 16, |
| 853 | child: Container( |
| 854 | padding: |
| 855 | const EdgeInsets.symmetric |
| 856 | decoration: BoxDecoration( |
| 857 | color: Colors.black.withOpacity |
| 858 | borderRadius: BorderRadius.circular( |
| 859 | ), |
| 860 | child: Row( |
| 861 | mainAxisSize: MainAxisSize.min, |
| 862 | children: [ |
| 863 | Icon( |
| 864 | Icons.info_outline, |
| 865 | color: Colors.white, |
| 866 | size: 16, |
| 867 | ), |
| 868 | const Gap(4) |
| 869 | Text( |
| 870 | 'Tap for details', |
| 871 | style: TextStyle( |
| 872 | fontSize: 12, |
| 873 | color: Colors.white, |
| 874 | fontWeight: FontWeight.w500, |
| 875 | ), |
| 876 | ), |
| 877 | ], |
| 878 | ), |
| 879 | ), |
| 880 | ), |
| 881 | ], |
| 882 | ), |
| 883 | ), |
| 884 | ); |
| 885 | } |
| 886 | |
| 887 | void _showAircraftStatsBottomSheet(AircraftStatsEntity |
| 888 | final theme = Theme. |
| 889 | final colorScheme = theme.colorScheme; |
| 890 | |
| 891 | showModalBottomSheet( |
| 892 | context: context, |
| 893 | backgroundColor: Colors.transparent, |
| 894 | isScrollControlled: true, |
| 895 | builder: (context) => Container( |
| 896 | constraints: BoxConstraints( |
| 897 | maxHeight: MediaQuery.of(context) |
| 898 | ), |
| 899 | decoration: BoxDecoration( |
| 900 | color: colorScheme.surface, |
| 901 | borderRadius: const BorderRadius. |
| 902 | ), |
| 903 | child: Column( |
| 904 | mainAxisSize: MainAxisSize.min, |
| 905 | children: [ |
| 906 | // Handle bar |
| 907 | Container( |
| 908 | margin: const EdgeInsets. |
| 909 | width: 40, |
| 910 | height: 4, |
| 911 | decoration: BoxDecoration( |
| 912 | color: colorScheme.onSurfaceVariant.withOpacity( |
| 913 | borderRadius: BorderRadius.circular( |
| 914 | ), |
| 915 | ), |
| 916 | // Header |
| 917 | Padding( |
| 918 | padding: const EdgeInsets. |
| 919 | child: Row( |
| 920 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 921 | children: [ |
| 922 | Text( |
| 923 | 'Aircraft Statistics', |
| 924 | style: TextStyle( |
| 925 | fontSize: 24, |
| 926 | fontWeight: FontWeight.bold, |
| 927 | color: colorScheme.onSurface, |
| 928 | ), |
| 929 | ), |
| 930 | IconButton( |
| 931 | icon: Icon(Icons. |
| 932 | onPressed: () => Navigator.of |
| 933 | ), |
| 934 | ], |
| 935 | ), |
| 936 | ), |
| 937 | // Content |
| 938 | Flexible( |
| 939 | child: SingleChildScrollView( |
| 940 | padding: const EdgeInsets. |
| 941 | child: Column( |
| 942 | crossAxisAlignment: CrossAxisAlignment.start, |
| 943 | children: [ |
| 944 | // Most Common Tail Number |
| 945 | if (aircraftStats.mostCommonTailNumber.isNotEmpty) ...[ |
| 946 | _buildTailNumberCard( |
| 947 | 'Most Common Tail Number', |
| 948 | aircraftStats.mostCommonTailNumber, |
| 949 | aircraftStats.mostCommonTailNumberCount.toInt(), |
| 950 | ), |
| 951 | const Gap(16) |
| 952 | ], |
| 953 | |
| 954 | // Median Age |
| 955 | if (aircraftStats.medianAge != null) ... |
| 956 | _buildStatRow( |
| 957 | 'Median Age', |
| 958 | '${aircraftStats.medianAge!. |
| 959 | ), |
| 960 | const Gap(16) |
| 961 | ], |
| 962 | |
| 963 | // Youngest and Oldest Aircraft |
| 964 | if (aircraftStats.youngestAircraft != null || |
| 965 | aircraftStats.oldestAircraft != null) ...[ |
| 966 | Text( |
| 967 | 'Aircraft Age Records', |
| 968 | style: TextStyle( |
| 969 | fontSize: 18, |
| 970 | fontWeight: FontWeight.bold, |
| 971 | color: colorScheme.onSurface, |
| 972 | ), |
| 973 | ), |
| 974 | const Gap(12) |
| 975 | if (aircraftStats.youngestAircraft != null && |
| 976 | aircraftStats.oldestAircraft != null) ...[ |
| 977 | _buildAircraftImageOverlayCard( |
| 978 | 'Youngest', |
| 979 | aircraftStats.youngestAircraft!, |
| 980 | ), |
| 981 | const Gap(12) |
| 982 | _buildAircraftImageOverlayCard( |
| 983 | 'Oldest', |
| 984 | aircraftStats.oldestAircraft!, |
| 985 | ), |
| 986 | ] else if (aircraftStats.youngestAircraft != null |
| 987 | _buildAircraftImageOverlayCard( |
| 988 | 'Youngest', |
| 989 | aircraftStats.youngestAircraft!, |
| 990 | ) |
| 991 | else if (aircraftStats.oldestAircraft != null |
| 992 | _buildAircraftImageOverlayCard( |
| 993 | 'Oldest', |
| 994 | aircraftStats.oldestAircraft!, |
| 995 | ), |
| 996 | const Gap(16) |
| 997 | ], |
| 998 | |
| 999 | // Bottom padding |
| 1000 | const Gap(20) |
| 1001 | ], |
| 1002 | ), |
| 1003 | ), |
| 1004 | ), |
| 1005 | ], |
| 1006 | ), |
| 1007 | ), |
| 1008 | ); |
| 1009 | } |
| 1010 | |
| 1011 | Widget _buildTailNumberCard(String |
| 1012 | final theme = Theme. |
| 1013 | final colorScheme = theme.colorScheme; |
| 1014 | |
| 1015 | return Container( |
| 1016 | padding: const EdgeInsets. |
| 1017 | decoration: BoxDecoration( |
| 1018 | color: colorScheme.surfaceVariant, |
| 1019 | borderRadius: BorderRadius.circular( |
| 1020 | ), |
| 1021 | child: Row( |
| 1022 | children: [ |
| 1023 | Container( |
| 1024 | width: 48, |
| 1025 | height: 48, |
| 1026 | decoration: BoxDecoration( |
| 1027 | color: colorScheme.surface, |
| 1028 | borderRadius: BorderRadius.circular( |
| 1029 | ), |
| 1030 | child: Icon( |
| 1031 | Icons.confirmation_number, |
| 1032 | color: colorScheme.onSurfaceVariant, |
| 1033 | size: 24, |
| 1034 | ), |
| 1035 | ), |
| 1036 | const Gap(16) |
| 1037 | Expanded( |
| 1038 | child: Column( |
| 1039 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1040 | children: [ |
| 1041 | Text( |
| 1042 | label, |
| 1043 | style: TextStyle( |
| 1044 | fontSize: 12, |
| 1045 | color: colorScheme.onSurfaceVariant, |
| 1046 | fontWeight: FontWeight.w600, |
| 1047 | ), |
| 1048 | ), |
| 1049 | const Gap(4) |
| 1050 | Text( |
| 1051 | tailNumber, |
| 1052 | style: TextStyle( |
| 1053 | fontSize: 18, |
| 1054 | fontWeight: FontWeight.bold, |
| 1055 | color: colorScheme.onSurface, |
| 1056 | ), |
| 1057 | ), |
| 1058 | const Gap(4) |
| 1059 | Text( |
| 1060 | '$count flights', |
| 1061 | style: TextStyle( |
| 1062 | fontSize: 14, |
| 1063 | color: colorScheme.onSurfaceVariant, |
| 1064 | ), |
| 1065 | ), |
| 1066 | ], |
| 1067 | ), |
| 1068 | ), |
| 1069 | ], |
| 1070 | ), |
| 1071 | ); |
| 1072 | } |
| 1073 | |
| 1074 | Widget _buildStatRow(String |
| 1075 | final theme = Theme. |
| 1076 | final colorScheme = theme.colorScheme; |
| 1077 | |
| 1078 | return Container( |
| 1079 | padding: const EdgeInsets. |
| 1080 | decoration: BoxDecoration( |
| 1081 | color: colorScheme.surfaceVariant, |
| 1082 | borderRadius: BorderRadius.circular( |
| 1083 | ), |
| 1084 | child: Row( |
| 1085 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 1086 | children: [ |
| 1087 | Text( |
| 1088 | label, |
| 1089 | style: TextStyle( |
| 1090 | fontSize: 14, |
| 1091 | color: colorScheme.onSurfaceVariant, |
| 1092 | fontWeight: FontWeight.w600, |
| 1093 | ), |
| 1094 | ), |
| 1095 | Text( |
| 1096 | value, |
| 1097 | style: TextStyle( |
| 1098 | fontSize: 16, |
| 1099 | fontWeight: FontWeight.bold, |
| 1100 | color: colorScheme.onSurface, |
| 1101 | ), |
| 1102 | ), |
| 1103 | ], |
| 1104 | ), |
| 1105 | ); |
| 1106 | } |
| 1107 | |
| 1108 | Widget _buildAircraftImageOverlayCard( |
| 1109 | String label, AircraftWithAge aircraft) { |
| 1110 | final theme = Theme. |
| 1111 | final colorScheme = theme.colorScheme; |
| 1112 | |
| 1113 | return Container( |
| 1114 | height: 200, |
| 1115 | decoration: BoxDecoration( |
| 1116 | color: colorScheme.surfaceVariant, |
| 1117 | borderRadius: BorderRadius.circular( |
| 1118 | boxShadow: [ |
| 1119 | BoxShadow( |
| 1120 | color: Colors.black.withOpacity |
| 1121 | blurRadius: 8, |
| 1122 | offset: const Offset( |
| 1123 | ), |
| 1124 | ], |
| 1125 | ), |
| 1126 | child: ClipRRect( |
| 1127 | borderRadius: BorderRadius.circular( |
| 1128 | child: Stack( |
| 1129 | fit: StackFit.expand, |
| 1130 | children: [ |
| 1131 | // Aircraft Image |
| 1132 | if (aircraft.image != null && |
| 1133 | aircraft.image!.endsWith('.svg' |
| 1134 | ? SvgPicture.network( |
| 1135 | aircraft.image!, |
| 1136 | fit: BoxFit.contain, |
| 1137 | placeholderBuilder: (context) => Container( |
| 1138 | color: colorScheme.surfaceVariant, |
| 1139 | child: Center( |
| 1140 | child: Icon( |
| 1141 | Icons.flight, |
| 1142 | color: colorScheme.onSurfaceVariant, |
| 1143 | size: 48, |
| 1144 | ), |
| 1145 | ), |
| 1146 | ), |
| 1147 | ) |
| 1148 | : CachedNetworkImage( |
| 1149 | imageUrl: aircraft.image!, |
| 1150 | fit: BoxFit.contain, |
| 1151 | placeholder: (context, url) => Container |
| 1152 | color: colorScheme.surfaceVariant, |
| 1153 | child: Center( |
| 1154 | child: CircularProgressIndicator( |
| 1155 | color: colorScheme.primary, |
| 1156 | ), |
| 1157 | ), |
| 1158 | ), |
| 1159 | errorWidget: (context, url, error) => Container |
| 1160 | color: colorScheme.surfaceVariant, |
| 1161 | child: Center( |
| 1162 | child: Icon( |
| 1163 | Icons.flight, |
| 1164 | color: colorScheme.onSurfaceVariant, |
| 1165 | size: 48, |
| 1166 | ), |
| 1167 | ), |
| 1168 | ), |
| 1169 | ) |
| 1170 | else |
| 1171 | Container( |
| 1172 | color: colorScheme.surfaceVariant, |
| 1173 | child: Center( |
| 1174 | child: Icon( |
| 1175 | Icons.flight, |
| 1176 | color: colorScheme.onSurfaceVariant, |
| 1177 | size: 48, |
| 1178 | ), |
| 1179 | ), |
| 1180 | ), |
| 1181 | // Gradient Overlay |
| 1182 | Container( |
| 1183 | decoration: BoxDecoration( |
| 1184 | gradient: LinearGradient( |
| 1185 | begin: Alignment.topCenter, |
| 1186 | end: Alignment.bottomCenter, |
| 1187 | colors: [ |
| 1188 | Colors.transparent, |
| 1189 | Colors.black.withOpacity( |
| 1190 | ], |
| 1191 | ), |
| 1192 | ), |
| 1193 | ), |
| 1194 | // Label badge at top |
| 1195 | Positioned( |
| 1196 | top: 12, |
| 1197 | left: 12, |
| 1198 | child: Container( |
| 1199 | padding: |
| 1200 | const EdgeInsets.symmetric |
| 1201 | decoration: BoxDecoration( |
| 1202 | color: Colors.black.withOpacity |
| 1203 | borderRadius: BorderRadius.circular( |
| 1204 | ), |
| 1205 | child: Text( |
| 1206 | label, |
| 1207 | style: const TextStyle( |
| 1208 | fontSize: 12, |
| 1209 | color: Colors.white, |
| 1210 | fontWeight: FontWeight.w600, |
| 1211 | ), |
| 1212 | ), |
| 1213 | ), |
| 1214 | ), |
| 1215 | // Overlay Text |
| 1216 | Positioned( |
| 1217 | bottom: 0, |
| 1218 | left: 0, |
| 1219 | right: 0, |
| 1220 | child: Padding( |
| 1221 | padding: const EdgeInsets. |
| 1222 | child: Column( |
| 1223 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1224 | mainAxisSize: MainAxisSize.min, |
| 1225 | children: [ |
| 1226 | Text( |
| 1227 | aircraft.aircraftName, |
| 1228 | style: const TextStyle( |
| 1229 | fontSize: 18, |
| 1230 | fontWeight: FontWeight.bold, |
| 1231 | color: Colors.white, |
| 1232 | shadows: [ |
| 1233 | Shadow( |
| 1234 | offset: Offset(0, |
| 1235 | blurRadius: 3, |
| 1236 | color: Colors.black54, |
| 1237 | ), |
| 1238 | ], |
| 1239 | ), |
| 1240 | maxLines: 2, |
| 1241 | overflow: TextOverflow.ellipsis, |
| 1242 | ), |
| 1243 | const Gap(6) |
| 1244 | Row( |
| 1245 | children: [ |
| 1246 | if (aircraft.age != null) ... |
| 1247 | Icon( |
| 1248 | Icons.calendar_today, |
| 1249 | color: Colors.white.withOpacity |
| 1250 | size: 16, |
| 1251 | ), |
| 1252 | const Gap(4) |
| 1253 | Text( |
| 1254 | '${aircraft.age!. |
| 1255 | style: TextStyle( |
| 1256 | fontSize: 14, |
| 1257 | fontWeight: FontWeight.w600, |
| 1258 | color: Colors.white.withOpacity |
| 1259 | shadows: const [ |
| 1260 | Shadow( |
| 1261 | offset: Offset(0, |
| 1262 | blurRadius: 3, |
| 1263 | color: Colors.black54, |
| 1264 | ), |
| 1265 | ], |
| 1266 | ), |
| 1267 | ), |
| 1268 | const Gap(12) |
| 1269 | ], |
| 1270 | Icon( |
| 1271 | Icons.confirmation_number, |
| 1272 | color: Colors.white.withOpacity |
| 1273 | size: 16, |
| 1274 | ), |
| 1275 | const Gap(4) |
| 1276 | Text( |
| 1277 | aircraft.tailNumber, |
| 1278 | style: TextStyle( |
| 1279 | fontSize: 14, |
| 1280 | fontWeight: FontWeight.w500, |
| 1281 | color: Colors.white.withOpacity |
| 1282 | shadows: const [ |
| 1283 | Shadow( |
| 1284 | offset: Offset(0, |
| 1285 | blurRadius: 3, |
| 1286 | color: Colors.black54, |
| 1287 | ), |
| 1288 | ], |
| 1289 | ), |
| 1290 | ), |
| 1291 | ], |
| 1292 | ), |
| 1293 | ], |
| 1294 | ), |
| 1295 | ), |
| 1296 | ), |
| 1297 | ], |
| 1298 | ), |
| 1299 | ), |
| 1300 | ); |
| 1301 | } |
| 1302 | |
| 1303 | Widget _buildTopAirlinesSection(List |
| 1304 | final theme = Theme. |
| 1305 | final colorScheme = theme.colorScheme; |
| 1306 | |
| 1307 | // Sort airlines by flight count |
| 1308 | List<AirlineStatsEntity> sortedAirlines = |
| 1309 | sortedAirlines.sort((a, b) => b |
| 1310 | |
| 1311 | final maxFlights = sortedAirlines.isNotEmpty |
| 1312 | ? sortedAirlines |
| 1313 | .map((a) => a.flightCount) |
| 1314 | .reduce((a, b) => a |
| 1315 | : 1; |
| 1316 | |
| 1317 | return Column( |
| 1318 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1319 | children: [ |
| 1320 | Text( |
| 1321 | 'Top Airlines', |
| 1322 | style: TextStyle( |
| 1323 | fontSize: 20, |
| 1324 | fontWeight: FontWeight.w700, |
| 1325 | color: colorScheme.onSurface, |
| 1326 | ), |
| 1327 | ), |
| 1328 | const Gap(4) |
| 1329 | Text( |
| 1330 | '${airlines.length} |
| 1331 | style: TextStyle( |
| 1332 | fontSize: 13, |
| 1333 | color: colorScheme.onSurfaceVariant, |
| 1334 | fontWeight: FontWeight.w500, |
| 1335 | ), |
| 1336 | ), |
| 1337 | const Gap(16) |
| 1338 | // Airlines list with bars |
| 1339 | ...sortedAirlines.take(10) |
| 1340 | final normalizedValue = airline.flightCount / |
| 1341 | return Container( |
| 1342 | margin: const EdgeInsets. |
| 1343 | padding: const EdgeInsets. |
| 1344 | decoration: BoxDecoration( |
| 1345 | color: colorScheme.surfaceVariant, |
| 1346 | borderRadius: BorderRadius.circular( |
| 1347 | ), |
| 1348 | child: Row( |
| 1349 | children: [ |
| 1350 | // Airline logo WITHOUT background - respecting brand guidelines |
| 1351 | SizedBox( |
| 1352 | width: 24, |
| 1353 | height: 24, |
| 1354 | child: (airline.image != null && |
| 1355 | ? (airline.image!.endsWith |
| 1356 | ? SvgPicture.network( |
| 1357 | airline.image!, |
| 1358 | fit: BoxFit.contain, |
| 1359 | placeholderBuilder: (context) => Icon( |
| 1360 | Icons.flight, |
| 1361 | color: colorScheme.onSurfaceVariant, |
| 1362 | size: 24, |
| 1363 | ), |
| 1364 | ) |
| 1365 | : CachedNetworkImage( |
| 1366 | imageUrl: airline.image!, |
| 1367 | fit: BoxFit.contain, |
| 1368 | errorWidget: (context, url, error) { |
| 1369 | if (airline.airlineIata.isNotEmpty) { |
| 1370 | return CachedNetworkImage( |
| 1371 | imageUrl: |
| 1372 | "https://airlabs.co/img/airline/m/${airline.airlineIata} |
| 1373 | fit: BoxFit.contain, |
| 1374 | errorWidget: (context, url, error) => Icon |
| 1375 | Icons.flight, |
| 1376 | color: colorScheme.onSurfaceVariant, |
| 1377 | size: 24), |
| 1378 | ); |
| 1379 | } |
| 1380 | return Icon(Icons |
| 1381 | color: colorScheme.onSurfaceVariant, |
| 1382 | size: 24); |
| 1383 | }, |
| 1384 | )) |
| 1385 | : (airline.airlineIata.isNotEmpty |
| 1386 | ? CachedNetworkImage( |
| 1387 | imageUrl: |
| 1388 | "https://airlabs.co/img/airline/m/${airline.airlineIata} |
| 1389 | fit: BoxFit.contain, |
| 1390 | errorWidget: (context, url, error) => Icon |
| 1391 | Icons.flight, |
| 1392 | color: colorScheme.onSurfaceVariant, |
| 1393 | size: 24, |
| 1394 | ), |
| 1395 | ) |
| 1396 | : Icon(Icons. |
| 1397 | color: colorScheme.onSurfaceVariant, size: 24 |
| 1398 | ), |
| 1399 | const Gap(12) |
| 1400 | Expanded( |
| 1401 | child: Column( |
| 1402 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1403 | children: [ |
| 1404 | Text( |
| 1405 | airline.airlineName, |
| 1406 | style: TextStyle( |
| 1407 | color: colorScheme.onSurface, |
| 1408 | fontWeight: FontWeight.w600, |
| 1409 | fontSize: 14, |
| 1410 | ), |
| 1411 | overflow: TextOverflow.ellipsis, |
| 1412 | ), |
| 1413 | const Gap(6) |
| 1414 | Row( |
| 1415 | children: [ |
| 1416 | Expanded( |
| 1417 | child: Container( |
| 1418 | height: 5, |
| 1419 | decoration: BoxDecoration( |
| 1420 | color: colorScheme.surface, |
| 1421 | borderRadius: BorderRadius.circular( |
| 1422 | ), |
| 1423 | child: FractionallySizedBox( |
| 1424 | alignment: Alignment.centerLeft, |
| 1425 | widthFactor: normalizedValue, |
| 1426 | child: Container( |
| 1427 | decoration: BoxDecoration( |
| 1428 | color: colorScheme.primary, |
| 1429 | borderRadius: BorderRadius.circular( |
| 1430 | ), |
| 1431 | ), |
| 1432 | ), |
| 1433 | ), |
| 1434 | ), |
| 1435 | const Gap(8) |
| 1436 | Text( |
| 1437 | '${airline.flightCount} |
| 1438 | style: TextStyle( |
| 1439 | color: colorScheme.onSurface, |
| 1440 | fontWeight: FontWeight.w700, |
| 1441 | fontSize: 13, |
| 1442 | ), |
| 1443 | ), |
| 1444 | ], |
| 1445 | ), |
| 1446 | ], |
| 1447 | ), |
| 1448 | ), |
| 1449 | ], |
| 1450 | ), |
| 1451 | ); |
| 1452 | }).toList(), |
| 1453 | ], |
| 1454 | ); |
| 1455 | } |
| 1456 | |
| 1457 | Widget _buildTopAirportsSection(List |
| 1458 | final theme = Theme. |
| 1459 | final colorScheme = theme.colorScheme; |
| 1460 | |
| 1461 | final maxCount = airports.isNotEmpty |
| 1462 | ? airports.map((a) => a |
| 1463 | : 1; |
| 1464 | |
| 1465 | return Column( |
| 1466 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1467 | children: [ |
| 1468 | Text( |
| 1469 | 'Top Airports', |
| 1470 | style: TextStyle( |
| 1471 | fontSize: 20, |
| 1472 | fontWeight: FontWeight.w700, |
| 1473 | color: colorScheme.onSurface, |
| 1474 | ), |
| 1475 | ), |
| 1476 | const Gap(4) |
| 1477 | Text( |
| 1478 | '${airports.length} |
| 1479 | style: TextStyle( |
| 1480 | fontSize: 13, |
| 1481 | color: colorScheme.onSurfaceVariant, |
| 1482 | fontWeight: FontWeight.w500, |
| 1483 | ), |
| 1484 | ), |
| 1485 | const Gap(16) |
| 1486 | ...airports.take(10) |
| 1487 | final normalizedValue = airport.departureCount / |
| 1488 | return Container( |
| 1489 | margin: const EdgeInsets. |
| 1490 | padding: const EdgeInsets. |
| 1491 | decoration: BoxDecoration( |
| 1492 | color: colorScheme.surfaceVariant, |
| 1493 | borderRadius: BorderRadius.circular( |
| 1494 | ), |
| 1495 | child: Row( |
| 1496 | children: [ |
| 1497 | Container( |
| 1498 | width: 48, |
| 1499 | height: 48, |
| 1500 | decoration: BoxDecoration( |
| 1501 | color: colorScheme.primaryContainer, |
| 1502 | borderRadius: BorderRadius.circular( |
| 1503 | ), |
| 1504 | child: Center( |
| 1505 | child: Text( |
| 1506 | airport.airportCode, |
| 1507 | style: TextStyle( |
| 1508 | color: colorScheme.onPrimaryContainer, |
| 1509 | fontWeight: FontWeight.w700, |
| 1510 | fontSize: 12, |
| 1511 | ), |
| 1512 | ), |
| 1513 | ), |
| 1514 | ), |
| 1515 | const Gap(12) |
| 1516 | Expanded( |
| 1517 | child: Column( |
| 1518 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1519 | children: [ |
| 1520 | Text( |
| 1521 | airport.airportName, |
| 1522 | style: TextStyle( |
| 1523 | color: colorScheme.onSurface, |
| 1524 | fontWeight: FontWeight.w600, |
| 1525 | fontSize: 14, |
| 1526 | ), |
| 1527 | overflow: TextOverflow.ellipsis, |
| 1528 | maxLines: 1, |
| 1529 | ), |
| 1530 | const Gap(6) |
| 1531 | Row( |
| 1532 | children: [ |
| 1533 | Expanded( |
| 1534 | child: Container( |
| 1535 | height: 5, |
| 1536 | decoration: BoxDecoration( |
| 1537 | color: colorScheme.surface, |
| 1538 | borderRadius: BorderRadius.circular( |
| 1539 | ), |
| 1540 | child: FractionallySizedBox( |
| 1541 | alignment: Alignment.centerLeft, |
| 1542 | widthFactor: normalizedValue, |
| 1543 | child: Container( |
| 1544 | decoration: BoxDecoration( |
| 1545 | color: colorScheme.primary, |
| 1546 | borderRadius: BorderRadius.circular( |
| 1547 | ), |
| 1548 | ), |
| 1549 | ), |
| 1550 | ), |
| 1551 | ), |
| 1552 | const Gap(8) |
| 1553 | Text( |
| 1554 | '${airport.departureCount} |
| 1555 | style: TextStyle( |
| 1556 | color: colorScheme.onSurface, |
| 1557 | fontWeight: FontWeight.w700, |
| 1558 | fontSize: 13, |
| 1559 | ), |
| 1560 | ), |
| 1561 | ], |
| 1562 | ), |
| 1563 | ], |
| 1564 | ), |
| 1565 | ), |
| 1566 | ], |
| 1567 | ), |
| 1568 | ); |
| 1569 | }).toList(), |
| 1570 | ], |
| 1571 | ); |
| 1572 | } |
| 1573 | |
| 1574 | Widget _buildTopRoutesSection(List |
| 1575 | final theme = Theme. |
| 1576 | final colorScheme = theme.colorScheme; |
| 1577 | |
| 1578 | final maxCount = routes.isNotEmpty |
| 1579 | ? routes.map((r) => r |
| 1580 | : 1; |
| 1581 | |
| 1582 | return Column( |
| 1583 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1584 | children: [ |
| 1585 | Text( |
| 1586 | 'Top Routes', |
| 1587 | style: TextStyle( |
| 1588 | fontSize: 20, |
| 1589 | fontWeight: FontWeight.w700, |
| 1590 | color: colorScheme.onSurface, |
| 1591 | ), |
| 1592 | ), |
| 1593 | const Gap(4) |
| 1594 | Text( |
| 1595 | '${routes.length} |
| 1596 | style: TextStyle( |
| 1597 | fontSize: 13, |
| 1598 | color: colorScheme.onSurfaceVariant, |
| 1599 | fontWeight: FontWeight.w500, |
| 1600 | ), |
| 1601 | ), |
| 1602 | const Gap(16) |
| 1603 | ...routes.take(10) |
| 1604 | final normalizedValue = route.flightCount / |
| 1605 | return Container( |
| 1606 | margin: const EdgeInsets. |
| 1607 | padding: const EdgeInsets. |
| 1608 | decoration: BoxDecoration( |
| 1609 | color: colorScheme.surfaceVariant, |
| 1610 | borderRadius: BorderRadius.circular( |
| 1611 | ), |
| 1612 | child: Row( |
| 1613 | children: [ |
| 1614 | Container( |
| 1615 | width: 48, |
| 1616 | height: 48, |
| 1617 | decoration: BoxDecoration( |
| 1618 | color: colorScheme.secondaryContainer, |
| 1619 | borderRadius: BorderRadius.circular( |
| 1620 | ), |
| 1621 | child: Icon( |
| 1622 | Icons.route, |
| 1623 | color: colorScheme.onSecondaryContainer, |
| 1624 | size: 20, |
| 1625 | ), |
| 1626 | ), |
| 1627 | const Gap(12) |
| 1628 | Expanded( |
| 1629 | child: Column( |
| 1630 | crossAxisAlignment: CrossAxisAlignment.start, |
| 1631 | children: [ |
| 1632 | Text( |
| 1633 | '${route.origin} |
| 1634 | style: TextStyle( |
| 1635 | color: colorScheme.onSurface, |
| 1636 | fontWeight: FontWeight.w600, |
| 1637 | fontSize: 14, |
| 1638 | ), |
| 1639 | overflow: TextOverflow.ellipsis, |
| 1640 | ), |
| 1641 | const Gap(6) |
| 1642 | Row( |
| 1643 | children: [ |
| 1644 | Expanded( |
| 1645 | child: Container( |
| 1646 | height: 5, |
| 1647 | decoration: BoxDecoration( |
| 1648 | color: colorScheme.surface, |
| 1649 | borderRadius: BorderRadius.circular( |
| 1650 | ), |
| 1651 | child: FractionallySizedBox( |
| 1652 | alignment: Alignment.centerLeft, |
| 1653 | widthFactor: normalizedValue, |
| 1654 | child: Container( |
| 1655 | decoration: BoxDecoration( |
| 1656 | color: colorScheme.primary, |
| 1657 | borderRadius: BorderRadius.circular( |
| 1658 | ), |
| 1659 | ), |
| 1660 | ), |
| 1661 | ), |
| 1662 | ), |
| 1663 | const Gap(8) |
| 1664 | Text( |
| 1665 | '${route.flightCount} |
| 1666 | style: TextStyle( |
| 1667 | color: colorScheme.onSurface, |
| 1668 | fontWeight: FontWeight.w700, |
| 1669 | fontSize: 13, |
| 1670 | ), |
| 1671 | ), |
| 1672 | ], |
| 1673 | ), |
| 1674 | ], |
| 1675 | ), |
| 1676 | ), |
| 1677 | ], |
| 1678 | ), |
| 1679 | ); |
| 1680 | }).toList(), |
| 1681 | ], |
| 1682 | ); |
| 1683 | } |
| 1684 | } |