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